I have wrote a class (a snippet is below) which have some data members where i put data from the Client Side. I should send this data through Web Services where is a class which includes my data members, but has more data members that my class.
I should cast from my type into another type.
The problem is that i don’t know how to access data members to take data from.
all my data are into this object “OBJ”:
__XtraInvoiceInfo OBJ = new __XtraInvoiceInfo();
and , the Web Services’s type is “InvoiceWithEntriesInfo”
var convertedObj = new InvoiceWithEntriesInfo()
{
invoiceNumber = OBJ.BasicInfo.InvoiceNumber --> member is not access.
| Equals
Visual Studio suggests | GetHashCode
only these methods | GetType
| ToString
invoiceDate = OBJ.BasicInfo.InvoiceDate *--> member is not accessible
firstName = OBJ.Payer.FirstName *-->> not accessible
lastName = OBJ.Payer.LastName *-->> not accessible
catem = OBJ.Payer.Catem *-->> not accessible
};
error “member is not accessible” means *–> ‘object’ does not contain a definition for ‘InvoiceDate’ and no extension method ‘InvoiceDate’ accepting a first argument of type ‘object’ could be found (are you missing a using directive or an assembly reference?)
public sealed class __XtraInvoiceInfo
{
private long _payerType = -1;
public long PayerType
{
get
{
return this._payerType;
}
set
{
this._payerType = value;
if (value == Constants.NATURAL_PAYER)
{
this.Payer = new __NaturalInvoiceInfo();
}
}
}
public object Payer
{
get; set;
}
public object BasicInfo
{
get; set;
}
//-- Nested Types --
public sealed class __NaturalInvoiceInfo
{
public string FirstName
{
get; set;
}
public string LastName
{
get; set;
}
public long Catem
{
get; set;
}
}
public sealed class __BasicInvoiceInfo
{
public long InvoiceNumber
{
get; set;
}
public DateTime? InvoiceDate
{
get; set;
}
}
}
I made properties Payer and BasicInfo because through them i take data from Client and i made a subbinding into my members like this way:
model.BindModel(xii =>
{
var bindModel = new ValidationFrameBindModel<__XtraInvoiceInfo.__BasicInvoiceInfo>();
this.BindControls(bindModel);
model.BindModel<__XtraInvoiceInfo.__BasicInvoiceInfo>((x,b) => x.BasicInfo = b, bindModel);
});
Thank you so much!!! if you have the power to answer my question.
I’m ready to say more details if it is required.
Well this is the problem:
You’re only declaring the properties as being of type
object– why not give them more useful types? If you don’t know the types, how do you know what properties will be there? Can you create abstract base class or interface which declares all the properties you want to guarantee will be there? (It’s fairly hard to tell what you’re trying to do, to be honest.)If you’re using C# 4 and .NET 4 you could just make them dynamic:
Then accessing sub-properties will be bound at execution time against the actual type of object.
On a side-note, please don’t prefix type names with
__– the C# specification reserves identifiers using__for compiler-specific features. From section 2.4.2: