本文整理汇总了C#中Type.GetField方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetField方法的具体用法?C# Type.GetField怎么用?C# Type.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStaticNullForUdtType
// to support oracle types and other INUllable types that have static Null as field
internal static object GetStaticNullForUdtType(Type type)
{
object value;
if (!s_typeToNull.TryGetValue(type, out value))
{
System.Reflection.PropertyInfo propInfo = type.GetProperty("Null", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
if (propInfo != null)
value = propInfo.GetValue(null, null);
else
{
System.Reflection.FieldInfo fieldInfo = type.GetField("Null", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
if (fieldInfo != null)
{
value = fieldInfo.GetValue(null);
}
else
{
throw ExceptionBuilder.INullableUDTwithoutStaticNull(type.AssemblyQualifiedName);
}
}
lock (s_typeToNull)
{
//if(50 < TypeToNull.Count) {
// TypeToNull.Clear();
//}
s_typeToNull[type] = value;
}
}
return value;
}
示例2: Analyze
void Analyze( Type targettype )
{
Console.WriteLine( "analyzing " + targettype.ToString() + " ... " );
foreach( MemberInfo memberinfo in targettype.GetMembers() )
{
//Console.WriteLine( memberinfo.MemberType.ToString() + " " + memberinfo.Name );
if( memberinfo.MemberType == MemberTypes.Field )
{
//Console.WriteLine( memberinfo.Name );
FieldInfo fi = targettype.GetField( memberinfo.Name );
Console.WriteLine( "Field: " + memberinfo.Name + " " + fi.FieldType + " isliteral " + fi.IsLiteral.ToString() );
}
else if( memberinfo.MemberType == MemberTypes.Property )
{
//Console.WriteLine( memberinfo.Name );
PropertyInfo pi = targettype.GetProperty( memberinfo.Name );
Console.WriteLine( "Property: " + pi.PropertyType + " " + memberinfo.Name );
}
else if( memberinfo.MemberType == MemberTypes.Method )
{
Console.WriteLine( memberinfo.MemberType.ToString() + " " + memberinfo.Name );
MethodBase methodbase = memberinfo as MethodBase;
MethodInfo methodinfo = memberinfo as MethodInfo;
Console.WriteLine( " returntype " + methodinfo.ReturnType.ToString() );
ParameterInfo[] parameterinfos = methodbase.GetParameters();
for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i ++ )
{
Console.WriteLine( " parameter " + parameterinfos[i].ParameterType + " " + parameterinfos[i].Name );
}
//Console.WriteLine( memberinfo.Name );
//MethodInfo mi = targettype.GetMethod( memberinfo.Name );
//Console.WriteLine( memberinfo.Name );
}
}
}
示例3: HasField
internal bool HasField(Type type, string name, BindingFlags bindingAttr)
{
if (this._targetFrameworkProvider == null)
{
return (type.GetField(name, bindingAttr) != null);
}
return (this._targetFrameworkProvider.GetReflectionType(type).GetField(name, bindingAttr) != null);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:ClientBuildManagerTypeDescriptionProviderBridge.cs
示例4: GetFields
public static FieldInfo[] GetFields(Type type, params string[] fieldNames)
{
FieldInfo[] fields = new FieldInfo[fieldNames.Length];
const BindingFlags Flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
for (int i = 0; i < fieldNames.Length; i++)
{
string name = fieldNames[i];
fields[i] = name == null ? null : type.GetField(name, Flags);
}
return fields;
}
示例5: HasField
internal bool HasField(Type type, string name, BindingFlags bindingAttr) {
if (_targetFrameworkProvider == null) {
FieldInfo runtimeFieldInfo = type.GetField(name, bindingAttr);
return runtimeFieldInfo != null;
}
Type reflectionType = _targetFrameworkProvider.GetReflectionType(type);
FieldInfo reflectionFieldInfo = reflectionType.GetField(name, bindingAttr);
return reflectionFieldInfo != null;
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:12,代码来源:ClientBuildManagerTypeDescriptionProviderBridge.cs
示例6: InitType
public static void InitType() {
if (realType == null) {
Assembly assembly = Assembly.GetAssembly(typeof(Editor));
realType = assembly.GetType("UnityEditor.AvatarPreview");
method_ctor = realType.GetConstructor(new Type[] { typeof(Animator), typeof(Motion)});
property_OnAvatarChangeFunc = realType.GetProperty("OnAvatarChangeFunc");
property_IKOnFeet = realType.GetProperty("IKOnFeet");
property_Animator = realType.GetProperty("Animator");
method_DoPreviewSettings = realType.GetMethod("DoPreviewSettings");
method_OnDestroy = realType.GetMethod("OnDestroy");
method_DoAvatarPreview = realType.GetMethod("DoAvatarPreview", new Type[] {typeof(Rect), typeof(GUIStyle)});
method_ResetPreviewInstance = realType.GetMethod("ResetPreviewInstance");
// method_CalculatePreviewGameObject = realType.GetMethod("CalculatePreviewGameObject", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
field_timeControl = realType.GetField("timeControl");
}
}
示例7: GetInstance
private static DbProviderServices GetInstance(Type providerType)
{
DebugCheck.NotNull(providerType);
const BindingFlags bindingFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
var instanceMember = providerType.GetProperty("Instance", bindingFlags)
?? (MemberInfo)providerType.GetField("Instance", bindingFlags);
if (instanceMember == null)
{
throw new InvalidOperationException(Strings.EF6Providers_InstanceMissing(providerType.AssemblyQualifiedName));
}
var providerInstance = instanceMember.GetValue() as DbProviderServices;
if (providerInstance == null)
{
throw new InvalidOperationException(Strings.EF6Providers_NotDbProviderServices(providerType.AssemblyQualifiedName));
}
return providerInstance;
}
示例8: GetFieldList
public static List<object> GetFieldList(Type type)
{
List<object> list = new List<object>();
foreach (int val in Enum.GetValues(type))
{
string name = Enum.GetName(type, val);
object[] attrs = type.GetField(name).GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
if (attrs != null && attrs.Length > 0)
{
string description = ((System.ComponentModel.DescriptionAttribute)attrs[0]).Description;
var e = new { Name = name, Value = val, Description = description };
list.Add(e);
}
}
return list;
}
示例9: GetField
public static FieldInfo GetField(Type type, string name)
{
Requires.NotNull(type, "type");
return type.GetField(name);
}
示例10: VerifyCustomAttribute
private void VerifyCustomAttribute(CustomAttributeBuilder builder, Type attributeType, FieldInfo[] namedFields, object[] fieldValues)
{
AssemblyName assemblyName = new AssemblyName("VerificationAssembly");
AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
assembly.SetCustomAttribute(builder);
object[] customAttributes = assembly.GetCustomAttributes(attributeType).ToArray();
Assert.Equal(1, customAttributes.Length);
object customAttribute = customAttributes[0];
for (int i = 0; i < namedFields.Length; ++i)
{
FieldInfo field = attributeType.GetField(namedFields[i].Name);
object expected = field.GetValue(customAttribute);
object actual = fieldValues[i];
Assert.Equal(expected, actual);
}
}
示例11: LocalBoxStorage
internal LocalBoxStorage(LambdaCompiler compiler, ParameterExpression variable)
: base(compiler, variable)
{
_boxType = typeof(StrongBox<>).MakeGenericType(variable.Type);
_boxValueField = _boxType.GetField("Value");
_boxLocal = compiler.GetNamedLocal(_boxType, variable);
}
示例12: GetDeclarationString
string GetDeclarationString( Type targettype, string basetypename, MemberInfo memberinfo )
{
if( memberinfo.MemberType == MemberTypes.Field )
{
FieldInfo fi = targettype.GetField( memberinfo.Name );
if( !fi.IsLiteral ) // ignore constants
{
// headerfile.WriteLine( " " + "mono_field_get_value( monoobject, mono_class_get_field_from_name (thisclass, \"" + memberinfo.Name + "\"), &(" + nativeobjectname + "->" + memberinfo.Name + " ) );" );
}
}
else if( memberinfo.MemberType == MemberTypes.Property )
{
PropertyInfo pi = targettype.GetProperty( memberinfo.Name );
string thismethoddeclaration = "";
thismethoddeclaration += CsTypeToCppTypeString( pi.PropertyType, true ) + " get_" + memberinfo.Name;
thismethoddeclaration += "()";
return thismethoddeclaration;
}
else if( memberinfo.MemberType == MemberTypes.Method )
{
if( memberinfo.Name.IndexOf( "get_" ) != 0 ) // ignore property accessors
{
MethodBase methodbase = memberinfo as MethodBase;
MethodInfo methodinfo = memberinfo as MethodInfo;
ParameterInfo[] parameterinfos = methodbase.GetParameters();
string thismethoddeclaration = "";
thismethoddeclaration += CsTypeToCppTypeString( methodinfo.ReturnType, true ) + " ";
thismethoddeclaration += methodinfo.Name;
thismethoddeclaration += "( ";
for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i++ )
{
thismethoddeclaration += CsTypeToCppTypeString( parameterinfos[i].ParameterType, false ) + " " + parameterinfos[i].Name;
if( i < parameterinfos.GetUpperBound(0) )
{
thismethoddeclaration += ", ";
}
}
thismethoddeclaration += " )";
return thismethoddeclaration;
}
}
return "";
}
示例13: GetDefaultAttribute
// Get the default attribute value of a particular type.
protected Attribute GetDefaultAttribute(Type attributeType)
{
FieldInfo field = attributeType.GetField
("Default", BindingFlags.Public | BindingFlags.Static);
if(field != null)
{
return (Attribute)(field.GetValue(null));
}
else
{
Attribute attr;
attr = (Attribute)(Activator.CreateInstance(attributeType));
if(attr != null && attr.IsDefaultAttribute())
{
return attr;
}
else
{
return null;
}
}
}
示例14: ElementBoxStorage
internal ElementBoxStorage(Storage array, int index, ParameterExpression variable)
: base(array.Compiler, variable)
{
_array = array;
_index = index;
_boxType = typeof(StrongBox<>).MakeGenericType(variable.Type);
_boxValueField = _boxType.GetField("Value");
}
示例15: VerifyCustomAttribute
private bool VerifyCustomAttribute(CustomAttributeBuilder builder, Type attributeType, FieldInfo[] fieldNames, object[] fieldValues)
{
AssemblyName asmName = new AssemblyName("VerificationAssembly");
bool retVal = true;
AssemblyBuilder asmBuilder = AssemblyBuilder.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
asmBuilder.SetCustomAttribute(builder);
object[] customAttributes = asmBuilder.GetCustomAttributes(attributeType).Select(a => (object)a).ToArray();
// We just support one custom attribute case
if (customAttributes.Length != 1)
return false;
object customAttribute = customAttributes[0];
for (int i = 0; i < fieldNames.Length; ++i)
{
FieldInfo field = attributeType.GetField(fieldNames[i].Name);
object expected = field.GetValue(customAttribute);
object actual = fieldValues[i];
if (expected == null)
{
if (actual != null)
{
retVal = false;
break;
}
}
else
{
if (!expected.Equals(actual))
{
retVal = false;
break;
}
}
}
return retVal;
}