本文整理汇总了C#中DTO.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DTO.GetType方法的具体用法?C# DTO.GetType怎么用?C# DTO.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DTO
的用法示例。
在下文中一共展示了DTO.GetType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDataShapedObject
public object CreateDataShapedObject(DTO.Expense expense, List<string> lstOfFields)
{
if (!lstOfFields.Any())
{
return expense;
}
else
{
// create a new ExpandoObject & dynamically create the properties for this object
ExpandoObject objectToReturn = new ExpandoObject();
foreach (var field in lstOfFields)
{
// need to include public and instance, b/c specifying a binding flag overwrites the
// already-existing binding flags.
var fieldValue = expense.GetType()
.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
.GetValue(expense, null);
// add the field to the ExpandoObject
((IDictionary<String, Object>)objectToReturn).Add(field, fieldValue);
}
return objectToReturn;
}
}
示例2: CreateDataShapeObject
public object CreateDataShapeObject(DTO.ExpenseGroup expenseGroup, List<string> lstFields)
{
List<string> lstFieldsIncluded = new List<string>(lstFields);
if (!lstFieldsIncluded.Any())
{
return expenseGroup;
}
else
{
var lstExpenseFields = lstFieldsIncluded.Where(s => s.Contains("expenses")).ToList();
bool returnPartialExpense = lstFieldsIncluded.Any() && !lstFieldsIncluded.Contains("expenses");
if (returnPartialExpense)
{
lstFieldsIncluded.RemoveRange(lstExpenseFields);
lstExpenseFields = lstExpenseFields.Select(f => f.Substring(f.IndexOf(".") + 1)).ToList();
}
else
{
lstExpenseFields.Remove("expenses");
lstFieldsIncluded.RemoveRange(lstExpenseFields);
}
ExpandoObject objToReturn = new ExpandoObject();
foreach (var field in lstFieldsIncluded)
{
var fieldValue = expenseGroup.GetType()
.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
.GetValue(expenseGroup, null);
((IDictionary<string, object>)objToReturn).Add(field, fieldValue);
}
if(returnPartialExpense)
{
List<object> expenses = new List<object>();
foreach(var expense in expenseGroup.Expenses)
{
expenses.Add(expenseFactory.CreateDataShapeObject(expense, lstExpenseFields));
}
((IDictionary<string, object>)objToReturn).Add("expenses", expenses);
}
return objToReturn;
}
}
示例3: CreateDataShapedObject
public object CreateDataShapedObject(DTO.Expense expense, List<string> fields)
{
if (!fields.Any())
{
return expense;
}
ExpandoObject objectToReturn = new ExpandoObject();
foreach (string field in fields)
{
var fieldValue = expense.GetType()
.GetProperty(field, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.GetValue(expense, null);
((IDictionary<string, object>)objectToReturn).Add(field, fieldValue);
//objectToReturn.field = fieldValue;
}
return objectToReturn;
}
示例4: CreateDataShapedObject
public object CreateDataShapedObject(DTO.ExpenseGroup expenseGroup, List<string> listOfFields)
{
var lstOfFieldsToWorkWith = new List<string>(listOfFields);
if (!lstOfFieldsToWorkWith.Any())
{
return expenseGroup;
}
var lstOfExpenseFileds = lstOfFieldsToWorkWith.Where(x => x.Contains("expenses")).ToList();
bool returnPartialExpense = lstOfExpenseFileds.Any() && !lstOfExpenseFileds.Contains("expenses");
if (returnPartialExpense)
{
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFileds);
lstOfExpenseFileds = lstOfExpenseFileds.Select(x => x.Substring(x.IndexOf(".") + 1)).ToList();
}
else
{
lstOfExpenseFileds.Remove("expenses");
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFileds);
}
var objectToReturn = new ExpandoObject();
foreach (var field in lstOfFieldsToWorkWith)
{
var fieldValue =
expenseGroup.GetType()
.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
.GetValue(expenseGroup, null);
((IDictionary<string, object>)objectToReturn).Add(field, fieldValue);
}
if (returnPartialExpense)
{
var expenses = expenseGroup.Expenses.Select(expense => this.expenseFactory.CreateDataShapedObject(expense, lstOfExpenseFileds)).ToList();
((IDictionary<string, object>)objectToReturn).Add("expenses", expenses);
}
return objectToReturn;
}
示例5: CreateDataShapeObject
public object CreateDataShapeObject(DTO.Expense expense, List<string> lstFields)
{
if (!lstFields.Any())
{
return expense;
}
else
{
ExpandoObject objToReturn = new ExpandoObject();
foreach(var field in lstFields)
{
var fieldValue = expense.GetType()
.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
.GetValue(expense, null);
((IDictionary<string, object>)objToReturn).Add(field, fieldValue);
}
return objToReturn;
}
}
示例6: CreateDataShapedObject
public object CreateDataShapedObject(DTO.Expense expense, List<string> lstOfFields)
{
if (!lstOfFields.Any())
{
return expense;
}
else
{
// an object whose members can be dynamically removed and added at run-time
ExpandoObject objectToReturn = new ExpandoObject();
foreach (var field in lstOfFields)
{
// reflection
var fieldValue = expense
.GetType().GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
.GetValue(expense, null);
((IDictionary<string, object>)objectToReturn).Add(field, fieldValue);
}
return objectToReturn;
}
}
示例7: CreateDataShapedObject
public object CreateDataShapedObject(DTO.ExpenseGroup expenseGroup, List<string> lstOfFields)
{
// work with a new instance, as we'll manipulate this list in this method
List<string> lstOfFieldsToWorkWith = new List<string>(lstOfFields);
if (!lstOfFieldsToWorkWith.Any())
{
return expenseGroup;
}
else
{
// does it include any expense-related field?
var lstOfExpenseFields = lstOfFieldsToWorkWith.Where(f => f.Contains("expenses")).ToList();
// if one of those fields is "expenses", we need to ensure the FULL expense is returned. If
// it's only subfields, only those subfields have to be returned.
bool returnPartialExpense = lstOfExpenseFields.Any() && !lstOfExpenseFields.Contains("expenses");
// if we don't want to return the full expense, we need to know which fields
if (returnPartialExpense)
{
// remove all expense-related fields from the list of fields,
// as we will use the CreateDateShapedObject function in ExpenseFactory
// for that.
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFields);
lstOfExpenseFields = lstOfExpenseFields.Select(f => f.Substring(f.IndexOf(".") + 1)).ToList();
}
else
{
// we shouldn't return a partial expense, but the consumer might still have
// asked for a subfield together with the main field, ie: expense,expense.id. We
// need to remove those subfields in that case.
lstOfExpenseFields.Remove("expenses");
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFields);
}
// create a new ExpandoObject & dynamically create the properties for this object
// if we have an expense
ExpandoObject objectToReturn = new ExpandoObject();
foreach (var field in lstOfFieldsToWorkWith)
{
// need to include public and instance, b/c specifying a binding flag overwrites the
// already-existing binding flags.
var fieldValue = expenseGroup.GetType()
.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
.GetValue(expenseGroup, null);
// add the field to the ExpandoObject
((IDictionary<String,Object>)objectToReturn).Add(field, fieldValue);
}
if (returnPartialExpense)
{
// add a list of expenses, and in that, add all those expenses
List<object> expenses = new List<object>();
foreach (var expense in expenseGroup.Expenses)
{
expenses.Add(expenseFactory.CreateDataShapedObject(expense, lstOfExpenseFields));
}
((IDictionary<String, Object>)objectToReturn).Add("expenses", expenses);
}
return objectToReturn;
}
}
示例8: CreateDataShapedObject
public object CreateDataShapedObject(DTO.ExpenseGroup expenseGroup, List<string> listOfFields)
{
List<string> lstOfFieldsToWorkWith = new List<string>(listOfFields);
if (!lstOfFieldsToWorkWith.Any())
{
return expenseGroup;
}
else
{
//does it include any expense-related fields?
var lstOfExpenseFields = lstOfFieldsToWorkWith.Where(f => f.Contains("expenses")).ToList();
//if one of those fields is "expense", ensure the full expanse is returned
//otherwise only those subfields needed to be returned.
bool returnPartialExpense = lstOfExpenseFields.Any() && !lstOfExpenseFields.Contains("expenses");
//If full expense is not to be returned then spec which fields should be
if (returnPartialExpense)
{
//remove expense fields from the list
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFields);
lstOfExpenseFields = lstOfExpenseFields.Select(f => f.Substring(f.IndexOf(".") + 1)).ToList();
}
else
{
//don't return a partial expense
//client can still ask for subfield together with main field, ie: expese,expense.id
//remove those subfields in that case
lstOfExpenseFields.Remove("expenses");
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFields);
}
//dynaically create properties for this object:
ExpandoObject objectToReturn = new ExpandoObject();
foreach (string field in lstOfFieldsToWorkWith)
{
var fieldValue = expenseGroup
.GetType()
.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
.GetValue(expenseGroup, null);
((IDictionary<string, object>)objectToReturn).Add(field, fieldValue);
}
if (returnPartialExpense)
{
//add a list of expenses and their collections
List<object> expenses = new List<object>();
foreach (var expense in expenseGroup.Expenses)
{
expenses.Add(expenseFactory.CreateDataShapeObject(expense, lstOfExpenseFields));
}
((IDictionary<string, object>)objectToReturn).Add("expenses", expenses);
}
return objectToReturn;
}
}
示例9: CreateDataShapedObject
private object CreateDataShapedObject(DTO.ExpenseGroup expenseGroup, List<string> lstOfFields)
{
const string EXPENSES = "expenses";
List<string> lstOfFieldsToWorkWith = new List<string>(lstOfFields);
if (!lstOfFieldsToWorkWith.Any())
{
return expenseGroup;
}
else
{
var lstOfExpenseFields = lstOfFieldsToWorkWith.Where(f => f.Contains("expenses")).ToList();
bool returnPartialExpense = lstOfExpenseFields.Any() && !lstOfExpenseFields.Contains("expenses");
if (returnPartialExpense)
{
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFields);
lstOfExpenseFields = lstOfExpenseFields.Select(f => f.Substring(f.IndexOf('.') + 1)).ToList();
}
else
{
lstOfExpenseFields.Remove(EXPENSES);
lstOfFieldsToWorkWith.RemoveRange(lstOfExpenseFields);
}
ExpandoObject objectToReturn = new ExpandoObject();
foreach (string field in lstOfFieldsToWorkWith)
{
var value = expenseGroup.GetType().
GetProperty(field, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.GetValue(expenseGroup, null);
((IDictionary<string, object>)objectToReturn)[field] = value;
}
if (returnPartialExpense)
{
List<object> expenses = new List<object>();
foreach (var expense in expenseGroup.Expenses)
{
expenses.Add(expenseFactory.CreateDataShapedObject(expense, lstOfExpenseFields));
}
((IDictionary<String, Object>)objectToReturn).Add("expenses", expenses);
}
return objectToReturn;
}
}