Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interfaces to some basic objects to allow for the use of generics #2

Open
greyknight79 opened this issue Feb 3, 2022 · 0 comments

Comments

@greyknight79
Copy link

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
				}
			}
		}
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant