|
If you want to break your application logic into smaller units, you put them in classes and package them as class libraries. If you are talking about breaking a single class into smaller manageable units, you can use partial classes.
|
|
|
|
|
they're called "assemblies" in .Net. Just create a class library project in your solution, and start adding classes to it. To use the classes in that library, you have to include htis line at the top of your file:
using MyLibraryNameSpace;
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
John Simmons / outlaw programmer wrote: you have to include htis line
No you don't, but he will need a reference.
|
|
|
|
|
PIEBALDconsult wrote: No you don't, but he will need a reference.
Actually, both a reference to the asembly and the using statment.
|
|
|
|
|
Shameel wrote: the using statment
Is not required and only weak developers use them.
|
|
|
|
|
PIEBALDconsult wrote: not required
Technically, yes.
But this code
using Com.Company.Suite.Product.Version.Module;
MyClass c1 = new MyClass();
is more readable by an order of magnitude than this code
Com.Company.Suite.Product.Version.Module.MyClass c1 = new Com.Company.Suite.Product.Version.Module.MyClass();
|
|
|
|
|
Shameel wrote: is more readable
I disagree, especially when code snippets are published here.
|
|
|
|
|
Code snippets with references to 3rd-party/programmer-created namespaces is kinda pointless anyway.
And who are you calling weak?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
PIEBALDconsult wrote: I disagree, especially when code snippets are published here.
Well, the vast majority of code that we write goes into some commercial project rather than CP posts.
Repeating the fully qualified type name of class everywhere it is used makes no sense especially when VS (and SD for that matter) tell you the fully qualified type name just by hovering the mouse over it.
|
|
|
|
|
Shameel wrote: the vast majority of code that we write goes into some commercial project
rather than CP posts
Yet the vast majority of code I see that I didn't write is in CP posts.
Shameel wrote: VS (and SD
Which I don't use if I can avoid it. I also prefer to print out code so I can review it away from the computer.
|
|
|
|
|
Agree 100%. Always use the full name.
|
|
|
|
|
I think another way to "frame" this question ... if my intuition is on-line here ... is to ask: how can I design, or re-design, my getting-very-big project into functional units, or: how can I determine a set of "organic criteria" which to use as an "organizing principle" to divide my project into logical "chunks" which, in the long run, contribute to program extension, maintenance, and de-bugging (and lend themselves to unit-testing in "isolation" ?).
All the "tools" mentioned here, including "Partial Classes," "Class Libraries," etc. are valuable.
... edit in appreciative response to feedback from PiebaldConsult ...
Please note: in Visual Studio the option to create a "Class Library" is one that appears when you create a new Solution, and also appears as an option when you choose to add a "New Project" to an existing "Solution." The question of whether a "Solution," which "begins life" as "only" a "Class Library," is, semantically, a "Solution," or a "Project" ... we'll we won't touch that one ...
... end edit ...
You create it, compile it, and, then, to use it "externally," you must reference it, by adding a Reference to the compiled .dll via the Solution Explorer/ References / Add Reference facility. The location of that compiled .dll can be anywhere: and the Add Reference dialog will let you browse to find it.
Once the Reference is added: you do not need to have a 'using' statement for it to be accessed.
The one "tool," not mentioned here, that may also be useful in "encapsulating functional units,"
is using NameSpaces: within one solution you can add Classes, etc., and encapsulate them in the scope of a different NameSpace.
In that case, to access the "whatever inside" that NameSpace, you will need to have a "using" statement in your Form or whatever it is that requires access. Or, you can avoid having a "using," statement kby using a "fully qualified" reference: Example:
using SpecialNameSpace;
SpecialClass theSpecialClass = new SpecialClass();
SpecialNameSpace.SpecialClass theSpecialClass = new SpecialNameSpace.SpecialClass();
However, when your solution, with multiple NameSpaces, is compiled, the resulting .exe incorporates everything: no separate files are created just by using different NameSpaces.
I have never experimented with trying to import a compiled class library dll into another class library, but, come to think of, I think I will ~
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
BillWoodruff wrote: it is a type of Solution
It is a type of project. A solution may contain many projects of various types. And you can add a project of class library type to an existing solution.
|
|
|
|
|
+5 Absolutely correct: interestingly, I've never created a Class Library that way.
I have edited my response to incorporate your feedback, thanks.
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
YOU'RE WEAK!
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
“Keep me away from the wisdom which does not cry, the philosophy which does not laugh and the greatness which does not bow before children.”
Kahlil Gibran
Happy Holidays, John !
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Hi,
I'm using iTextSharp to read text contents and coordinates of text from PDF. Able to read the text. For few pdfs, it is reading on letter by letter basis.
For eg, instead of reading the below text completely, its retuning F, R, O, M, S, E, R,...
"FROM SERVICER CASSA DI RISPARMIO DI CESENA SPA"
please guide me to solve this issue. Thanks in advance
Code:
private void button1_Click(object sender, EventArgs e)
{
PdfReader reader = new PdfReader(@"C:\Original.pdf");
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
int numberOfPages = reader.NumberOfPages;
for (int num = 1; num <= numberOfPages; num++)
{
TextWithFontExtractionStategy S = new TextWithFontExtractionStategy();
string F = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, num, S);
}
}
public class TextInfo
{
private double x;
private double y;
private double iwidth;
private double iheight;
private string strtext;
public double left
{
get
{
return x;
}
set
{
x = value;
}
}
public double top
{
get
{
return y;
}
set
{
y = value;
}
}
public double width
{
get
{
return iwidth;
}
set
{
iwidth = value;
}
}
public double height
{
get
{
return iheight;
}
set
{
iheight = value;
}
}
public string Text
{
get
{
return strtext;
}
set
{
strtext = value;
}
}
public StringBuilder strXML = new StringBuilder();
public string getTextInfo()
{
string strTextInfo = "";
strTextInfo = "top:" + y.ToString() + "left:" + x.ToString() + "width:" + iwidth.ToString() + "height:" + iheight.ToString() + "Text:" + strtext;
string xmlString = "<text top=\""+y.ToString()+" left=\""+x.ToString()+" width=\""+iwidth.ToString()+" height=\""+iheight.ToString()+" font=\"0\">" + strtext +"</text>";
return strTextInfo;
}
}
public class TextWithFontExtractionStategy : iTextSharp.text.pdf.parser.ITextExtractionStrategy
{
private List<TextInfo> lstTextInfo = new List<TextInfo>();
private StringBuilder result = new StringBuilder();
private enum TextRenderMode
{
FillText = 0,
StrokeText = 1,
FillThenStrokeText = 2,
Invisible = 3,
FillTextAndAddToPathForClipping = 4,
StrokeTextAndAddToPathForClipping = 5,
FillThenStrokeTextAndAddToPathForClipping = 6,
AddTextToPaddForClipping = 7
}
public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
{
TextInfo txtInfo = getTextInfo(renderInfo);
Console.WriteLine(txtInfo.getTextInfo());
lstTextInfo.Add(txtInfo);
}
private TextInfo getTextInfo(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
{
TextInfo txtInfo = new TextInfo();
Vector asStartpoint = renderInfo.GetAscentLine().GetStartPoint();
Vector asEndpoint = renderInfo.GetAscentLine().GetEndPoint();
Vector dsStartPoint = renderInfo.GetDescentLine().GetEndPoint();
txtInfo.left = Math.Round(asStartpoint[0]);
txtInfo.top = Math.Round(612-asStartpoint[1]);
txtInfo.height = Math.Round(asStartpoint[1] - dsStartPoint[1]);
txtInfo.width = Math.Round(asEndpoint[0] - asStartpoint[0]);
txtInfo.Text = renderInfo.GetText();
if (txtInfo.Text.Contains("closin")) { }
return txtInfo;
}
public string GetResultantText()
{
return result.ToString();
}
public List<TextInfo> GetTextInfo()
{
return lstTextInfo;
}
public void BeginTextBlock() { }
public void EndTextBlock() { }
public void RenderImage(ImageRenderInfo renderInfo) { }
}
modified 27-Dec-11 4:53am.
|
|
|
|
|
my data set contaions some colums containing bool values when i populate the dataset to DEV EXpress Grid view it shows these values as check boxes...i dont want to shw check boxes rathe the actual data....what should i do? .
|
|
|
|
|
What do you want to display the data as?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
can you show us your code of creating gridview ?
|
|
|
|
|
|
Use an icon file (.ico). Icon files support multiple image sizes within the same file.
|
|
|
|
|
Goal: I am wanting to write a C# program that will pull data from a website to help me exercise what I have learned and to further learn OOP and the .Net framework a little better.
Background: The website is a fantasy game that allows you to buy stocks of movies before they come out and the final stock price is the total amount the movie made in theaters.
What I Have: A class for each stock, a static class for the portfolio which holds a List<stock> containing each instance of stock, a static class called netConnection with a method for logging in and a method for pulling data from other pages, and a static class called dataProcessor that processes the data from netConnection.
Now I'm not brand new at programming but am having a little trouble figuring out how to setup my plan for my program with OOP in mind. I guess the easiest way to get advice would be to just post my code and let others give me ideas on ways to improve. I have seen other snippets that use their net connection in an OOP way but I'm not sure if I did it right since my connection doesn't need to be persistent.
modified 26-Dec-11 4:37am.
|
|
|
|
|
The first question you have to ask yourself is - "Does the code work as desired?" If you can answer *yes*, the code is done, and you can start a new version that refactors the code into something "better".
IMHO, you're over-using regular expressions (and it's generally considered ill-advised to use regular expressions to parse HTML).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
The code works as desired but it also worked as desired when it was less than beautiful. heh. What should I use to parse html?
|
|
|
|
|