当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetProperty方法代码示例

本文整理汇总了C#中Type.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetProperty方法的具体用法?C# Type.GetProperty怎么用?C# Type.GetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.GetProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Solution

 static Solution()
 {
     s_SolutionParser = Type.GetType("Microsoft.Build.Construction.SolutionParser, Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", false, false);
     if (s_SolutionParser != null)
     {
         s_SolutionParser_solutionReader = s_SolutionParser.GetProperty("SolutionReader", BindingFlags.NonPublic | BindingFlags.Instance);
         s_SolutionParser_projects = s_SolutionParser.GetProperty("Projects", BindingFlags.NonPublic | BindingFlags.Instance);
         s_SolutionParser_parseSolution = s_SolutionParser.GetMethod("ParseSolution", BindingFlags.NonPublic | BindingFlags.Instance);
     }
 }
开发者ID:ColdenCullen,项目名称:GLIF,代码行数:10,代码来源:Solution.cs

示例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 );
         }
     }
 }
开发者ID:achoum,项目名称:spring,代码行数:35,代码来源:AbicWrapperGenerator.cs

示例3: 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;
 }
开发者ID:dotnet,项目名称:corefx,代码行数:31,代码来源:SqlUDTStorage.cs

示例4: getObjectFromDict

        private static Object getObjectFromDict(Type objectType, Dictionary<string, object> dataDictionary)
        {

            Object tempObject = Activator.CreateInstance(objectType);
            foreach (string key in dataDictionary.Keys)
            {

                foreach (PropertyInfo propInfo in objectType.GetProperties())
                {
                    if (propInfo.Name.ToLower().Equals(key.ToLower()))
                    {

                        PropertyInfo newProp = objectType.GetProperty(propInfo.Name, BindingFlags.Public | BindingFlags.Instance);
                        newProp.GetValue(tempObject,null);

                        if (propInfo.PropertyType.IsEnum) //Enum
                        {
                            object enumObj = Enum.Parse(propInfo.PropertyType, dataDictionary[key].ToString());
                            newProp.SetValue(tempObject, enumObj,null);
                        }
                        else if (propInfo.PropertyType.GetInterfaces().Contains(typeof(ICollection)))
                        {
                            List<long> indexList = getListFromObject(dataDictionary[key]);
                            newProp.SetValue(tempObject, indexList, null);
                        }
                        else
                        {
                            newProp.SetValue(tempObject, dataDictionary[key], null);
                        }
                    }
                }
            }

            return tempObject;
        }
开发者ID:mengtest,项目名称:UnityRPG,代码行数:35,代码来源:DataLoader.cs

示例5: RelationsInspectorLink

	// ctor. retrieves types, properties and methods
	static RelationsInspectorLink()
	{
		windowType = GetTypeInAssembly( riWindowTypeName, riAssemblyName );
		if ( windowType == null )
		{
			return; // this happens when RI is not installed. no need for an error msg here.
		}

		api1Property = windowType.GetProperty( api1PropertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty );
		if ( api1Property == null )
		{
			Debug.LogError( "Failed to retrieve API1 property of type " + windowType );
			return;
		}

		api1Type = GetTypeInAssembly( riAPI1TypeName, riAssemblyName );
		if ( api1Type == null )
		{
			Debug.LogError( "Failed to retrieve API1 type" );
			return;
		}

		api1ResetTargetsMethod = api1Type.GetMethod( api1ResetTargetsMethodName, api1ResetTargetsArguments );
		if ( api1ResetTargetsMethod == null )
		{
			Debug.LogError( "Failed to retrieve API method ResetTargets(object[],Type,bool)" );
			return;
		}

		RIisAvailable = true;
	}
开发者ID:riscvul,项目名称:SCP_Game_Prototype,代码行数:32,代码来源:RelationsInspectorLink.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");
		}
	}
开发者ID:fakestuff,项目名称:MecanimEventSystem,代码行数:17,代码来源:EditorInternalClassWrapper.cs

示例7: SetModule

 void SetModule(object instance, Type type)
 {
     var property = type.GetProperty<ModuleDefinition>("ModuleDefinition");
     if (property == null)
     {
         var message = string.Format("{0} must contain a public instance settable property named 'ModuleDefinition' of type 'Mono.Cecil.ModuleDefinition'.", type.GetTypeName());
         throw new WeavingException(message);
     }
     property.SetValue(instance, ModuleDefinition, null);
 }
开发者ID:CloudMetal,项目名称:Fody,代码行数:10,代码来源:WeaverInitialiser.cs

示例8: ClientReflectionHelper

		static ClientReflectionHelper ()
		{
			SystemAssembly = typeof (Uri).Assembly;
			web_header_collection = SystemAssembly.GetType ("System.Net.WebHeaderCollection");
			headers_all_keys = web_header_collection.GetProperty ("AllKeys").GetGetMethod ();

			headers_get = web_header_collection.GetMethod ("Get", new Type [] { typeof (string) });
			headers_set = web_header_collection.GetMethod ("Set", new Type [] { typeof (string), typeof (string) });

			Type network_credential = SystemAssembly.GetType ("System.Net.NetworkCredential");
			network_credential_ctor = network_credential.GetConstructor (new Type [] { typeof (string), typeof (string), typeof (string) });
		}
开发者ID:kangaroo,项目名称:moon,代码行数:12,代码来源:ClientReflectionHelper.cs

示例9: HasProperty

    internal bool HasProperty(Type type, string name, BindingFlags bindingAttr, Type returnType, Type[] types)
    {
        if (_targetFrameworkProvider == null) {
            PropertyInfo runtimePropInfo = type.GetProperty(name, bindingAttr, null /* binder */, returnType, types, null /* modifiers */);
            return runtimePropInfo != null;
        }

        Type reflectionType = GetReflectionType(type);
        Type[] reflectionTypes = GetReflectionTypes(types);

        PropertyInfo reflectionPropertyInfo = reflectionType.GetProperty(name, bindingAttr, null /* binder */, returnType, reflectionTypes, null /* modifiers */);

        return reflectionPropertyInfo != null;
    }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:14,代码来源:ClientBuildManagerTypeDescriptionProviderBridge.cs

示例10: GetEventHandler

	private Delegate GetEventHandler(EventInfo ei, Type eaType, string fieldToAssign)
	{
		ParameterExpression senderParam = Expression.Parameter(typeof(object), "sender");
		ParameterExpression eventArgsParam = Expression.Parameter(eaType, "e");
		Delegate handler = Expression.Lambda(ei.EventHandlerType,
			Expression.Assign(
				Expression.Field(Expression.Constant(this), this.GetType().GetField(fieldToAssign)),
				Expression.Property(eventArgsParam, eaType.GetProperty("Value").GetGetMethod())
			),
			senderParam,
			eventArgsParam
		).Compile();
		return handler;
	}
开发者ID:kedarvaidya,项目名称:Expose.Fody,代码行数:14,代码来源:Helpers.cs

示例11: 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;
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:20,代码来源:ProviderServicesFactory.cs

示例12: DynamicPropertyAccessor

 public DynamicPropertyAccessor(Type type, string propertyName)
     : this(type.GetProperty(propertyName))
 {
 }
开发者ID:mbsky,项目名称:myextensions,代码行数:4,代码来源:DynamicPropertyAccessor.cs

示例13: GenerateFor

    void GenerateFor( Type targettype, string basetypename, string[]methodstoignore )
    {
        string[] splittargettypestring = targettype.ToString().Split(".".ToCharArray() );
        string namespacename = "";
        if( splittargettypestring.GetUpperBound(0) + 1 > 1 )
        {
            namespacename = splittargettypestring[ 0 ];
        }
        string typename = splittargettypestring[ splittargettypestring.GetUpperBound(0) ];
        //string basetypename = typename.Substring(1); // remove leading "I"
        string basefilename = "Abic" + typename + "Wrapper_generated";

        StreamWriter headerfile = new StreamWriter( basefilename + ".h", false );
        WriteHeaderComments( headerfile );

        // target code to generate for header:
        // AICALLBACK_API int UnitDef_get_id( const UnitDef *self );

        // target code to generate for cpp:
        // AICALLBACK_API int UnitDef_get_id( const UnitDef *self )
        // {
        //     return self->id;
        // }
        // StreamWriter cppfile = new StreamWriter( basefilename + ".cpp", false );
        //WriteHeaderComments( cppfile );
        foreach( MemberInfo memberinfo in targettype.GetMembers() )
        {
            if( !ArrayContains( methodstoignore, memberinfo.Name ) )
            {
                try
                {
                    string declarationstring = GetDeclarationString( targettype, basetypename, memberinfo );
                    if( declarationstring != "" )
                    {
                        // first we generate the string, throwing exceptions as appropriate
                        // then we write them to file if they worked out ok
                        // this needs to be atomic, so that we always have both header declaration + cpp definition, or neither
                        string cppdeclaration = "   " + declarationstring + "\n";
                        cppdeclaration += "   " + "{\n";
                        if( memberinfo.MemberType == MemberTypes.Property )
                        {
                            PropertyInfo pi = targettype.GetProperty( memberinfo.Name );
                            cppdeclaration += "   " + "   return " + basetypename + "_get_" + memberinfo.Name + "( self );\n"; // we can assume a property wont return void
                        }
                        else if( memberinfo.MemberType == MemberTypes.Method )
                        {
                            MethodInfo methodinfo = memberinfo as MethodInfo;
                            if( methodinfo.ReturnType != typeof( void ) )
                            {
                                cppdeclaration += "   " + "   return " + basetypename + "_" + memberinfo.Name + "( self ";
                            }
                            else
                            {
                                cppdeclaration += "   " + "   " + basetypename + "_" + memberinfo.Name + "( self ";
                            }

                            ParameterInfo[] parameterinfos = methodinfo.GetParameters();
                            for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i++ )
                            {
                                //if( i < parameterinfos.GetUpperBound(0) )
                                //{
                                    cppdeclaration += ", ";
                                //}
                                cppdeclaration += parameterinfos[i].Name;
                            }

                            cppdeclaration += "  );\n";
                        }
                        cppdeclaration += "   " + "}\n";
                        cppdeclaration += "\n";

                        //headerfile.WriteLine( declarationstring + ";" );
                        headerfile.Write( cppdeclaration );
                    }
                }
                catch( ExceptionCsTypeNotHandled e )
                {
                    Console.WriteLine("Ignoring " + memberinfo.MemberType.ToString() + " " + typename + "." + memberinfo.Name + " " + e.Message );
                }
                catch( Exception e )
                {
                    Console.WriteLine( e.ToString() );
                }
            }
        }

        headerfile.Close();
        //cppfile.Close();
    }
开发者ID:achoum,项目名称:spring,代码行数:89,代码来源:AbicWrapperGenerator.cs

示例14: 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 "";
    }
开发者ID:achoum,项目名称:spring,代码行数:44,代码来源:AbicWrapperGenerator.cs

示例15: BindToProjectedProperty

        /// <summary>Binds specified expression to a projected propety of a given index.</summary>
        /// <param name="projectedWrapperType">The type of the projected wrapper to bind to.</param>
        /// <param name="propertyIndex">The index of the projected property to bind to.</param>
        /// <param name="expression">The expression to bind to the property.</param>
        /// <returns>The newly create binding expression.</returns>
        private static MemberAssignment BindToProjectedProperty(Type projectedWrapperType, int propertyIndex, Expression expression)
        {
            Debug.Assert(
                typeof(ProjectedWrapper).IsAssignableFrom(projectedWrapperType), 
                "Trying to bind to a type which is not a projected wrapper.");
            Debug.Assert(
                propertyIndex < projectedPropertyNames.Length, 
                "Trying to bind to a too big property index.");

            return Expression.Bind(
                projectedWrapperType.GetProperty(projectedPropertyNames[propertyIndex]),
                expression);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:18,代码来源:ProjectedWrapper.cs


注:本文中的Type.GetProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。