Add interfaces to some basic objects to allow for the use of generics
Opened this issue · 0 comments
greyknight79 commented
Classes like CurrencyObjectType
and CurrencyObjectIDType
could really benefit from having a common interface designed for things that end in ObjectType
and ObjectIDType
as they are layed out the same no matter the prefix of the type on them.
This would allow for generic functions to be written so as not to repeat the same basic format of code as much.
For instance:
private static CurrencyObjectType BuildCurrencyReference() {
return new CurrencyObjectType {
ID = new List<CurrencyObjectIDType> {
new CurrencyObjectIDType {
type = "Currency_ID",
TypedValue = "USD"
}
}
};
}
private static Payment_TermsObjectType BuildPaymentTermsReference() {
return new Payment_TermsObjectType {
ID = new List<Payment_TermsObjectIDType> {
new Payment_TermsObjectIDType {
type = "Payment_Terms_ID",
TypedValue = "Immediate"
}
}
};
}
Could then be written as:
CurrencyObjectType currencyUSD = BuildTypeCollection<CurrencyObjectType, CurrencyObjectIDType>("Currency_ID","USD");
private static T BuildTypeCollection<T, TU>(string type, string value) where T : ObjectType where TU : ObjectIDType {
return new T {
ID = new List<TU> {
new TU {
type = type,
TypedValue = value
}
}
}
}