|
This could be done using reflection, but I would not recommend it as it adds a lot of overhead.
I would rather make the class responsible for assigning the values, using an interface like:
public interface IDynamicProperties {
string[] GetPropertyNames { get; }
void SetProperty(string name, object value);
}
The class to be populated could implement it like this:
public Customer : IDynamicProperties {
public int Id { get; private set; }
public string FirstName { get; private set; }
public string LastName { get; private set; }
public string[] GetPropertyNames{ get { return { "CustomerId", "FirstName", "LastName" } } }
public void SetProperty(string name, object value) {
switch (name) {
case "CustomerID": Id = (int)value; break;
case "FirstName": FirstName = (string)value; break;
case "LastName": LastName = (string)value; break;
}
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
This following console app attempts to use the PDFToImage class (at bottom of this post):
class MainClass
{
[STAThread]
public static void Main(string[] args)
{
if (args.Length < 6)
{
Console.WriteLine);
return;
}
using (StreamWriter sw = new StreamWriter(args[5]))
{
sw.WriteLine(transformPDFToImage(args[0]));
}
}
private static string transformPDFToImage(string input)
{
whatdoiwritehere?PDFToImage(input);...?
}
}
I've tried...
PDFToImage pdf2i = new PDFToImage(input);...but the compiler responds with The type 'org.pdfbox.PDFToImage' has no constructors defined(CS0143)
If I write...
PDFToImage pdf2i = new PDFToImage();...the compiler responds with 'pdf2i' is a 'variable' but is used like a 'method'(CS0118)
Thanks for any help.
For reference, here's the PDFToImage class definition (written in Java). (In my library, it's since been dotnetized, using IKVM, into a .NET-referenceable DLL): http://svn.apache.org/repos/asf/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/PDFToImage.java
modified on Sunday, January 11, 2009 4:59 PM
|
|
|
|
|
Correct the class has no constructors that take any parameters, so yes case #1 would be correct.
If you want to rewrite it in C# you would need something like this
public class PDFToImage<br />
{<br />
public PDFToImage() {}<br />
public PDFToImage(string input){ ... }<br />
public PDFToImage( [parameters] ) {... }<br />
public string TransformPDFToImage(...) { ... }<br />
}
only two letters away from being an asset
|
|
|
|
|
Does it go onto the module like this? (Please forgive me, I'm not an OO programmer.):
namespace pdf2jpeg
{
class MainClass
{
[STAThread]
public static void Main(string[] args)
{
if (args.Length < 6)
{
Console.WriteLine();
return;
}
using (StreamWriter sw = new StreamWriter(args[5]))
{
sw.WriteLine(transformPDFToImage(args[0]));
}
}
private static string transformPDFToImage(string input)
{
PDFToImage pdf2i = new PDFToImage();
}
}
public class PDFToImage
{
public PDFToImage() {}
public PDFToImage(string input){ ... }
public PDFToImage( [parameters] ) {... }
public string TransformPDFToImage(...) { ... }
}
}
How would I call that public class PDFToImage from within private static string transformPDFToImage(string input)?
Thanks for your help.
modified on Sunday, January 11, 2009 4:56 PM
|
|
|
|
|
First you need to complete the class, then you instantiate an instance, like you have, and call the method. If this is unfamiliar to you, you need to stop right now and do more studying on the concepts, language and environment.
only two letters away from being an asset
|
|
|
|
|
What you've written is actually incredibly helpful for me. Thank you again for replying to my post.
But may I ask how the calling statement should be written, if both "case" statements 1 and 2 are mistakenly written?
Also, how does one know whthr a class takes a constructor or not. Where did you glean that information?
|
|
|
|
|
e40s wrote: if both "case" statements 1 and 2 are mistakenly written?
What case statements?
e40s wrote: Also, how does one know whthr a class takes a constructor or not. Where did you glean that information?
You can't be serious?!? If you can't answer this you have no business trying to be a developer.
only two letters away from being an asset
|
|
|
|
|
What I can't believe is why you would even feel worthy of contributing to this board with an attitude like that. Are you one of those insecure types who views questions as stupid?
I come to this, brand new, from VBA; we don't use constructors. It's an innocent question that deserves respect and patience, not condescension and refusal to answer because of your insecurity.
I would prefer that you not reply to any questions I post in the future. Thanks.
modified on Sunday, January 11, 2009 10:24 PM
|
|
|
|
|
e40s wrote: questions as stupid?
not questions, only the people who ask them without knowledge.
e40s wrote: I would prefer that you not reply to any questions I post in the future.
I would prefer you not asking basic knowledge questions. Guess we can't get what we wish for.
only two letters away from being an asset
|
|
|
|
|
Hi,
I would like to suggest you buy an introductory book on C# and work your way through it.
That will take a few days but it will provide you with all the basic information you are going to need anyway, in a logical order and a consistent terminology; it will teach you all the new concepts and make you feel comfortable with C# much faster than any other way. So go to a book store (or visit Amazon, I prefer the book store though), look at a couple of books, and choose the one that looks most promising to you.
That is what I do for any new language or technology I want to learn.
The refinement is: buy two books, a tutorial and a reference book; and study the tutorial.
The reference book is not absolutely necessary, you can Google or use MSDN for detailed info;
but nothing can replace the tutorial or introductory book.
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.
modified on Friday, June 10, 2011 12:34 PM
|
|
|
|
|
This is a static class, so it seems that you must have a static method in there that returns an initialized version of the class. When you type in your class, type in PDFToImage pdf2i = PDFToImage. Intellisense should return the method you need.
|
|
|
|
|
Thanks for replying to my post. The IntelliSense dropdown contains not a single line of pdfbox-related object at all. I wish it did. The dropdown doesn't even list pdfbox itself.
I don't know if it's because these DLLs were IKVMed from Java bytecode or what.
But--oddly in the same IDE--the mouseover can inform the user, by mouseover caption, that PDFToImage is part of the org.pdfbox namespace. That much shows up.
(I'm using SharpDevelop.)
|
|
|
|
|
I think you should familiarize yourself with the environment and tools before proceeding; i.e. Pick up a basic .NET book and read a little.
only two letters away from being an asset
|
|
|
|
|
I am developing an application in Visual Studio C# 2008 Express Edition.
I need to have a password protected access to a dialog box containing a check box. the value of the check can be only modified if password is provided. The value of the check box should be always available to the application to check the status.
Please tell me how can I accomplish having a password protection to such data.
Thanks,
Karmendra
|
|
|
|
|
Add login to the application and check the credentials when displaying the dialog. It isn't that difficult and there are plenty of examples here and elsewhere. What have you tried so far?
only two letters away from being an asset
|
|
|
|
|
Hi there , i'm trying to create a class in C# to use my Sql operations but i'm facing some problems.
Although i'm using the code to import SQL objects(using system.data.sqlclient;) i can't declare variables such as Sqlcommand or sqlclient for ex.That way the class get's kind meaningless.How can i use them?
Thanks for your help and pacience as you will figure it out i'm learning C# i was a Vb6 coder.
|
|
|
|
|
You mean the compiler doesn't find the SqlCommand and other types? You need to add a reference to the System.Data.dll. In Visual Studio right click on the project and select "Add Reference".
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
|
|
I'm facing some problems with ObservableCollection constructor..
Any idea why this code is not working?
entity.Currencies = new ObservableCollection<CurrencyEntity>(CurreniesList.Where( c => c.IsSelected));
Note:
1. entity.Currencies is ObservableCollection<CurrencyEntity>().
2. CurrenciesList is ObservableCollection<CurrencyEntity>().
3. CurrencyEntity class has a proprety called "IsSelected".
Thanks in advance.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
|
|
|
|
|
ObservableCollection < T > 's constructor takes a List < T >, and not IEnumerable < T >, presumably because only then can it "observe" addition and removal of elements. Simply wrapping the result of CurrenciesList.Where in a list should solve the problem.
new ObservableCollection <CurrencyEntity>(
new List<CurrencyEntity>(currenciesList.Where(c => c.IsSelected)));
|
|
|
|
|
Hi Senthil,
Thanks but I'm still getting the error. There are 3 constructors[^] in ObservableCollection.
IEnumerable[^] is one of them.
Or, Am I missing something??
|
|
|
|
|
|
The error message is like it doesn't a constructor that takes 1 argument.
I'm using 3.5.... Am i referencing the wrong dll or need to import some namespaces? it's very strange
|
|
|
|