本文整理汇总了C#中System.Dynamic.ExpandoObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ExpandoObject.GetType方法的具体用法?C# ExpandoObject.GetType怎么用?C# ExpandoObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Dynamic.ExpandoObject
的用法示例。
在下文中一共展示了ExpandoObject.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultipleExpansions
public void MultipleExpansions()
{
var expression = "o";
dynamic o = new ExpandoObject();
o.Answer = 42;
var type = new DkmClrType((TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
// Dynamic View should appear after all other expansions.
var result = FormatResult(expression, value);
Verify(result,
EvalResult(expression, "{System.Dynamic.ExpandoObject}", "System.Dynamic.ExpandoObject", expression, DkmEvaluationResultFlags.Expandable));
Verify(GetChildren(result),
EvalResult("Class", "{System.Dynamic.ExpandoClass}", "System.Dynamic.ExpandoClass", "o.Class", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Property, DkmEvaluationResultAccessType.Internal),
EvalResult("LockObject", "{object}", "object", "o.LockObject", DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Data, DkmEvaluationResultAccessType.Internal),
EvalResult("System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, object>>.Count", "1", "int", "((System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, object>>)o).Count", DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Property, DkmEvaluationResultAccessType.Private),
EvalResult("System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, object>>.IsReadOnly", "false", "bool", "((System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, object>>)o).IsReadOnly", DkmEvaluationResultFlags.Boolean | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Property, DkmEvaluationResultAccessType.Private),
EvalResult("System.Collections.Generic.IDictionary<string, object>.Keys", "Count = 1", "System.Collections.Generic.ICollection<string> {System.Dynamic.ExpandoObject.KeyCollection}", "((System.Collections.Generic.IDictionary<string, object>)o).Keys", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Property, DkmEvaluationResultAccessType.Private),
EvalResult("System.Collections.Generic.IDictionary<string, object>.Values", "Count = 1", "System.Collections.Generic.ICollection<object> {System.Dynamic.ExpandoObject.ValueCollection}", "((System.Collections.Generic.IDictionary<string, object>)o).Values", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Property, DkmEvaluationResultAccessType.Private),
EvalResult("_count", "1", "int", "o._count", category: DkmEvaluationResultCategory.Data, access: DkmEvaluationResultAccessType.Private),
EvalResult("_data", "{System.Dynamic.ExpandoObject.ExpandoData}", "System.Dynamic.ExpandoObject.ExpandoData", "o._data", DkmEvaluationResultFlags.Expandable, DkmEvaluationResultCategory.Data, DkmEvaluationResultAccessType.Private),
EvalResult("_propertyChanged", "null", "System.ComponentModel.PropertyChangedEventHandler", "o._propertyChanged", category: DkmEvaluationResultCategory.Data, access: DkmEvaluationResultAccessType.Private),
EvalResult(Resources.StaticMembers, null, "", "System.Dynamic.ExpandoObject", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Class),
EvalResult(Resources.DynamicView, Resources.DynamicViewValueWarning, "", "o, dynamic", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
}
示例2: DynamicByTypeWrapper
public void DynamicByTypeWrapper()
{
var obj = new ExpandoObject();
((dynamic)obj).Foo = "bar";
var accessor = TypeAccessor.Create(obj.GetType());
Assert.AreEqual("bar", accessor[obj, "Foo"]);
accessor[obj, "Foo"] = "BAR";
string result = ((dynamic) obj).Foo;
Assert.AreEqual("BAR", result);
}
示例3: IsDynamicType_WhenGivenDynamicType_ReturnsTrue
public void IsDynamicType_WhenGivenDynamicType_ReturnsTrue()
{
// ARRANGE
var item = new ExpandoObject();
var type = item.GetType();
// ACT
var actual = type.IsDynamicType();
// ASSERT
Assert.IsTrue(actual);
}
示例4: Serialize
public void Serialize()
{
var Serializer = new JsonSerializer();
dynamic Object = new { A = 5, B = "ASDF" };
Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object));
Object = new TestObject { A = 5, B = "ASDF" };
Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object));
Object = new ExpandoObject();
Object.A = 5;
Object.B = "ASDF";
Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object));
Object = new Dynamo();
Object.A = 5;
Object.B = "ASDF";
Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object));
}
示例5: ExceptionTypeMember
public void ExceptionTypeMember()
{
var expression = "o";
dynamic o = new ExpandoObject();
var exception = new NotImplementedException();
o.Member = exception;
var type = new DkmClrType((TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
var result = FormatResult(expression, value);
Verify(result,
EvalResult(expression, "{System.Dynamic.ExpandoObject}", "System.Dynamic.ExpandoObject", expression, DkmEvaluationResultFlags.Expandable));
var dynamicView = GetChildren(result).Last();
Verify(dynamicView,
EvalResult(Resources.DynamicView, Resources.DynamicViewValueWarning, "", "o, dynamic", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
Verify(GetChildren(dynamicView),
EvalResult("Member", $"{{{exception.ToString()}}}", "System.NotImplementedException", "new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(o).Items[0]", DkmEvaluationResultFlags.ReadOnly));
}
示例6: MultipleMembers
public void MultipleMembers()
{
var expression = "o";
dynamic o = new ExpandoObject();
o.Philosophers = new object[] { "Pythagoras", "Lucretius", "Zeno" };
o.WhatsForDinner = "Crab Cakes";
o.NumForks = 2;
var type = new DkmClrType((TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
var result = FormatResult(expression, value);
Verify(result,
EvalResult(expression, "{System.Dynamic.ExpandoObject}", "System.Dynamic.ExpandoObject", expression, DkmEvaluationResultFlags.Expandable));
var dynamicView = GetChildren(result).Last();
Verify(dynamicView,
EvalResult(Resources.DynamicView, Resources.DynamicViewValueWarning, "", "o, dynamic", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
Verify(GetChildren(dynamicView),
EvalResult("NumForks", "2", "System.Int32", "new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(o).Items[0]", DkmEvaluationResultFlags.ReadOnly),
EvalResult("Philosophers", "{object[3]}", "System.Object[]", "new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(o).Items[1]", DkmEvaluationResultFlags.ReadOnly),
EvalResult("WhatsForDinner", "\"Crab Cakes\"", "System.String", "new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(o).Items[2]", DkmEvaluationResultFlags.ReadOnly));
}
示例7: DynamicTypeMember
public void DynamicTypeMember()
{
var expression = "o";
dynamic o = new ExpandoObject();
o.Pi = Math.PI;
o.OnAndOn = o;
var type = new DkmClrType((TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
var result = FormatResult(expression, value);
Verify(result,
EvalResult(expression, "{System.Dynamic.ExpandoObject}", "System.Dynamic.ExpandoObject", expression, DkmEvaluationResultFlags.Expandable));
var members = GetChildren(result);
var fullNameOnAndOn = "o";
var fullNamePi = "o";
// Expand 3 levels...
for (var i = 0; i < 3; i++)
{
var dynamicView = members.Last();
Verify(dynamicView,
EvalResult(Resources.DynamicView, Resources.DynamicViewValueWarning, "", $"{fullNameOnAndOn}, dynamic", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
members = GetChildren(dynamicView);
fullNamePi = $"new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView({fullNameOnAndOn}).Items[1]";
fullNameOnAndOn = $"new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView({fullNameOnAndOn}).Items[0]";
Verify(members,
EvalResult("OnAndOn", "{System.Dynamic.ExpandoObject}", "System.Dynamic.ExpandoObject", fullNameOnAndOn, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly),
EvalResult("Pi", "3.1415926535897931", "System.Double", fullNamePi, DkmEvaluationResultFlags.ReadOnly));
members = GetChildren(members[0]);
}
}
示例8: DynamicFormatSpecifier
public void DynamicFormatSpecifier()
{
var expression = "o";
dynamic o = new ExpandoObject();
o.Answer = 42;
var type = new DkmClrType((TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
var fullName = expression + ", dynamic";
var result = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));
Verify(result,
EvalResult(expression, Resources.DynamicViewValueWarning, "", fullName, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
Verify(GetChildren(result),
EvalResult("Answer", "42", "System.Int32", "new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(o).Items[0]", DkmEvaluationResultFlags.ReadOnly));
}
示例9: DynamicMetaObjectProviderDebugViewItemsException
public void DynamicMetaObjectProviderDebugViewItemsException()
{
var expression = "o";
var fullName = expression + ", dynamic";
dynamic o = new ExpandoObject();
o.Answer = 42;
DkmClrRuntimeInstance runtime = null;
Func<DkmClrValue> getExceptionValue = () => CreateDkmClrValue(new NotImplementedException(), evalFlags: DkmEvaluationResultFlags.ExceptionThrown);
runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(), getMemberValue: (_, m) => (m == "Items") ? getExceptionValue() : null);
var type = new DkmClrType(runtime, (TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
var result = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));
Verify(result,
EvalResult(expression, Resources.DynamicViewValueWarning, "", fullName, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
var members = GetChildren(result);
Assert.Equal(32, members.Length);
Verify(members[1],
EvalResult("HResult", "-2147467263", "int", null, category: DkmEvaluationResultCategory.Property, access: DkmEvaluationResultAccessType.Public));
getExceptionValue = () => CreateDkmClrValue(new NotImplementedException());
result = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));
Verify(result,
EvalResult(expression, Resources.DynamicViewValueWarning, "", fullName, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
members = GetChildren(result);
Assert.Equal(32, members.Length);
Verify(members[1],
EvalResult("HResult", "-2147467263", "int", "((System.Exception)new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(o).Items).HResult", category: DkmEvaluationResultCategory.Property, access: DkmEvaluationResultAccessType.Public));
}
示例10: DynamicMetaObjectProviderDebugViewItemsError
public void DynamicMetaObjectProviderDebugViewItemsError()
{
var expression = "o";
dynamic o = new ExpandoObject();
o.Answer = 42;
DkmClrRuntimeInstance runtime = null;
runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(),
getMemberValue: (_, m) => (m == "Items") ? CreateErrorValue(runtime.GetType(typeof(Array)), "Function evaluation timed out") : null);
var type = new DkmClrType(runtime, (TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
var fullName = expression + ", dynamic";
var result = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));
Verify(result,
EvalResult(expression, Resources.DynamicViewValueWarning, "", fullName, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
Verify(GetChildren(result),
EvalFailedResult(Resources.ErrorName, "Function evaluation timed out"));
}
示例11: DynamicTypeError
public void DynamicTypeError()
{
var expression = "o";
var obj = new ExpandoObject();
// Verify that things *work* in this scenario if there was no error in member access.
var value = CreateDkmClrValue(obj);
var fullName = expression + ", dynamic";
var result = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));
Verify(result,
EvalResult(expression, Resources.DynamicViewValueWarning, "", fullName, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
// Verify no Dynamic View if member access is changed to result in an error.
var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore());
value = CreateErrorValue(runtime.GetType(obj.GetType()), "Function evaluation timed out");
result = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));
Verify(result,
EvalFailedResult(expression, Resources.DynamicViewNotDynamic));
}
示例12: NoMembers
public void NoMembers()
{
var expression = "o";
dynamic o = new ExpandoObject();
var type = new DkmClrType((TypeImpl)o.GetType());
var value = CreateDkmClrValue((object)o, type);
var result = FormatResult(expression, value);
Verify(result,
EvalResult(expression, "{System.Dynamic.ExpandoObject}", "System.Dynamic.ExpandoObject", expression, DkmEvaluationResultFlags.Expandable));
var dynamicView = GetChildren(result).Last();
Verify(dynamicView,
EvalResult(Resources.DynamicView, Resources.DynamicViewValueWarning, "", "o, dynamic", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
Verify(GetChildren(dynamicView),
EvalFailedResult(Resources.ErrorName, DynamicDebugViewEmptyMessage));
}
示例13: ConvertToSource
/// <summary>
/// Converts to source.
/// </summary>
/// <param name="obj">The object.</param>
/// <param name="setName">Name of the set.</param>
/// <returns>SourceFieldList.</returns>
public static SourceFieldList ConvertToSource(ExpandoObject obj, string setName)
{
var properties = (IDictionary<string, object>) obj;
return ConvertToSource(obj.GetType().Name, properties, setName);
}
示例14: CoerceType_DictionaryToExpando_CoercesViaDictionaryCopy
public void CoerceType_DictionaryToExpando_CoercesViaDictionaryCopy()
{
var input = new Hashtable
{
{ "One", 1 },
{ "Two", 2 },
{ "Three", 3 },
{ "Four", 4 }
};
dynamic expected = new ExpandoObject();
expected.One = 1;
expected.Two = 2;
expected.Three = 3;
expected.Four = 4;
var settings = new DataReaderSettings();
var actual = new TypeCoercionUtility(settings, settings.AllowNullValueTypes).CoerceType(expected.GetType(), input);
Assert.Equal(expected, actual);
}