當前位置: 首頁>>代碼示例>>C#>>正文


C# Type.GetRuntimeProperties方法代碼示例

本文整理匯總了C#中System.Type.GetRuntimeProperties方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.GetRuntimeProperties方法的具體用法?C# Type.GetRuntimeProperties怎麽用?C# Type.GetRuntimeProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Type的用法示例。


在下文中一共展示了Type.GetRuntimeProperties方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProvideRules

        public IEnumerable<IValidationRule> ProvideRules(Type objectType, IEnumerable<string> standards)
        {
            List<IValidationRule> returnList = new List<IValidationRule>();
            List<Attribute> typeAttributes = new List<Attribute>(objectType.GetTypeInfo().GetCustomAttributes());

            foreach (IAttributeValidationRuleProvider attributeValidationRuleProvider in attributeValidationRuleProviders)
            {
                returnList.AddRange(attributeValidationRuleProvider.ProvideRules(objectType, typeAttributes, null, null));
            }

            foreach (PropertyInfo runtimeProperty in objectType.GetRuntimeProperties())
            {
                if (!runtimeProperty.CanRead ||
                     !runtimeProperty.GetMethod.IsPublic ||
                     runtimeProperty.GetMethod.IsStatic)
                {
                    continue;
                }

                foreach (IAttributeValidationRuleProvider attributeValidationRuleProvider in attributeValidationRuleProviders)
                {
                    List<Attribute> propertyAttributes = new List<Attribute>(runtimeProperty.GetCustomAttributes());

                    returnList.AddRange(attributeValidationRuleProvider.ProvideRules(objectType, typeAttributes, runtimeProperty, propertyAttributes));
                }
            }

            return returnList;
        }
開發者ID:jrjohn,項目名稱:Grace,代碼行數:29,代碼來源:AttributeValidationRuleProvider.cs

示例2: OnBuildRequest

        protected override JsTypeDefinition OnBuildRequest(Type t)
        {
            JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name);

            //only instance /public method /prop***
            //MethodInfo[] methods = t.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var methods = t.GetRuntimeMethods();
            foreach (var met in methods)
            {
                if(!met.IsStatic && met.IsPublic)
                {
                    typedefinition.AddMember(new JsMethodDefinition(met.Name, met));
                }
            }

            //var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var properties = t.GetRuntimeProperties();
            //TODO finding GetProperties with BindingFlags
            foreach (var property in properties)
            {
                typedefinition.AddMember(new JsPropertyDefinition(property.Name, property)); 
            }

            return typedefinition;
        }
開發者ID:prepare,項目名稱:HTML-Renderer,代碼行數:25,代碼來源:JsTypeDefinitionBuilder.cs

示例3: GetProperties

    internal static IEnumerable<PropertyInfo> GetProperties(Type type) {
#if MONO || UNITY
      return type.GetProperties();
#else
      return type.GetRuntimeProperties();
#endif
    }
開發者ID:cnbcyln,項目名稱:Parse-SDK-dotNET,代碼行數:7,代碼來源:ReflectionHelpers.cs

示例4: SerializeMembers

 /// <summary>
 /// Serialize a list of members from the object.
 /// </summary>
 /// <param name="serializer">The serializer to utilize when serializing the values.</param>
 /// <param name="type">The type of the object to serialize the members from.</param>
 /// <param name="value">The value to serialize the members from.</param>
 /// <returns>The list of members that make up the object.</returns>
 static IEnumerable<JsonMember> SerializeMembers(IJsonSerializer serializer, Type type, object value)
 {
     foreach (var property in type.GetRuntimeProperties().Where(p => p.CanRead))
     {
         yield return new JsonMember(serializer.FieldNamingStrategy.GetName(property.Name), serializer.SerializeValue(property.GetValue(value)));
     }
 }
開發者ID:cosullivan,項目名稱:Hypermedia,代碼行數:14,代碼來源:ComplexConverter.cs

示例5: ValidateContract

        public static void ValidateContract(Type contract)
        {
            if (contract == null)
            {
                throw new ArgumentNullException(nameof(contract));
            }

            if (!contract.GetTypeInfo().IsInterface)
            {
                throw new InvalidOperationException(
                    $"Unable to use class '{contract.FullName}' as contract because only interface contracts are supported.");
            }

            if (contract.GetRuntimeProperties().Any())
            {
                throw new InvalidOperationException(
                    $"Unable to use interface '{contract.FullName}' as contract because it contains properties.");
            }

            IEnumerable<MethodInfo> methods = contract.GetRuntimeMethods().ToList();
            if (methods.Count() != methods.Select(m=>m.Name).Distinct().Count())
            {
                throw new InvalidOperationException(
                    $"Unable to use interface '{contract.FullName}' as contract because it methods with the same name.");
            }
        }
開發者ID:geffzhang,項目名稱:Bolt,代碼行數:26,代碼來源:BoltFramework.cs

示例6: GetAllDependants

        /// <summary>
        /// Recursively gathers the list of all properties which depend
        /// on the provided property, whether directly or indirectly.
        /// Each dependent property will only be included once, so
        /// multiple or circular dependencies will not result in multiple
        /// <see cref="INotifyPropertyChanged.PropertyChanged"/> events.
        /// </summary>
        /// <param name="targetType">The object in which the properties reside.</param>
        /// <param name="propertyName">
        /// The name of the property for which to collect all dependent properties.
        /// </param>
        /// <returns>
        /// Returns the list of all properties which are directly or
        /// indirectly dependent on the original property.
        /// </returns>
        public static IEnumerable<PropertyInfo> GetAllDependants(Type targetType, string propertyName)
        {
            //Retrieve the Property Info for the specified property
            var propertyInfo = targetType.GetRuntimeProperties()
                .First(x => x.Name == propertyName);

            IEnumerable<PropertyInfo> oldResults = null;
            IEnumerable<PropertyInfo> results = new[] { propertyInfo };
            do
            {
                oldResults = results;

                var dependancies = from input in results
                                   from dependancy in GetDirectDependants(targetType, input.Name)
                                   select dependancy;

                //Create union of current results with "new" results,
                //making sure to remove duplicates
                results = results.Union(dependancies)
                    .GroupBy((x) => x.Name)
                    .Select(grp => grp.First());
            }
            while (results.Count() > oldResults.Count());

            //Return results not including the original property name
            return results.Where(x => (x.Name != propertyName));
        }
開發者ID:btowntkd,項目名稱:Tourney2015MatchListViewer,代碼行數:42,代碼來源:DependsOnAttribute.cs

示例7: FormatCompledValue

        private static string FormatCompledValue(object value, int depth, Type type)
        {
            if (depth == MAX_DEPTH)
                return String.Format("{0} {{ ... }}", type.Name);

            var fields = type.GetRuntimeFields()
                             .Where(f => f.IsPublic && !f.IsStatic)
                             .Select(f => new { name = f.Name, value = WrapAndGetFormattedValue(() => f.GetValue(value), depth) });
            var properties = type.GetRuntimeProperties()
                                 .Where(p => p.GetMethod != null && p.GetMethod.IsPublic && !p.GetMethod.IsStatic)
                                 .Select(p => new { name = p.Name, value = WrapAndGetFormattedValue(() => p.GetValue(value), depth) });
            var parameters = fields.Concat(properties)
                                   .OrderBy(p => p.name)
                                   .Take(MAX_OBJECT_PARAMETER_COUNT + 1)
                                   .ToList();

            if (parameters.Count == 0)
                return String.Format("{0} {{ }}", type.Name);

            var formattedParameters = String.Join(", ", parameters.Take(MAX_OBJECT_PARAMETER_COUNT)
                                                                  .Select(p => String.Format("{0} = {1}", p.name, p.value)));

            if (parameters.Count > MAX_OBJECT_PARAMETER_COUNT)
                formattedParameters += ", ...";

            return String.Format("{0} {{ {1} }}", type.Name, formattedParameters);
        }
開發者ID:Tofudebeast,項目名稱:xunit,代碼行數:27,代碼來源:ArgumentFormatter.cs

示例8: GetSheet

        public static Sheet GetSheet(Type t)
        {
            var sheetAttr = (SheetAttribute)t.GetAttribute(typeof(SheetAttribute));
            var sheetName = sheetAttr != null ? sheetAttr.Name : t.Name;
            var definedColumn = sheetAttr != null ? sheetAttr.DefinedColumn : "";
            var startingComments = sheetAttr != null && sheetAttr.StartingComments != null ? sheetAttr.StartingComments.ToList() : new List<string>();

            var properties = from property in t.GetRuntimeProperties()
                    where (property.GetMethod != null && property.GetMethod.IsPublic)
                || (property.SetMethod != null && property.SetMethod.IsPublic)
                || (property.GetMethod != null && property.GetMethod.IsStatic)
                || (property.SetMethod != null && property.SetMethod.IsStatic)
                select property;

            var columns = new List<Column>();
            foreach(var property in properties)
            {
                var ignore = property.GetCustomAttribute(typeof(IgnoredColumnAttribute), true);

                if (property.CanWrite && ignore == null)
                {
                    columns.Add(new Column(property));
                }
            }

            return new Sheet(sheetName, columns, definedColumn, startingComments);
        }
開發者ID:naokirin,項目名稱:Buffet,代碼行數:27,代碼來源:Sheet.cs

示例9: GetProperties

 public static List<PropertyInfo> GetProperties(Type type)
 {
     #if NETFX_CORE
     return type.GetRuntimeProperties().ToList();
     #else
     return type.GetProperties().ToList();
     #endif
 }
開發者ID:phicuong08,項目名稱:memorymatch,代碼行數:8,代碼來源:ReflectionHelper.cs

示例10: GetPublicInstanceProperties

 public IEnumerable<PropertyInfo> GetPublicInstanceProperties(Type mappedType)
 {
     return from p in mappedType.GetRuntimeProperties()
         where
             ((p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic) ||
              (p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic))
         select p;
 }
開發者ID:Reza1024,項目名稱:SQLite.Net-PCL,代碼行數:8,代碼來源:ReflectionServiceWinRT.cs

示例11: GetPrimaryKey

 public static string[] GetPrimaryKey(Type type) {
     return new MemberInfo[0]
         .Concat(type.GetRuntimeProperties())
         .Concat(type.GetRuntimeFields())
         .Where(m => m.GetCustomAttributes(true).Any(i => i.GetType().Name == "KeyAttribute"))
         .Select(m => m.Name)
         .OrderBy(i => i)
         .ToArray();
 }
開發者ID:DevExpress,項目名稱:DevExtreme.AspNet.Data,代碼行數:9,代碼來源:Utils.cs

示例12: Apply

        public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
        {
            if (schema == null || schema.properties == null || type == null) return;

            bool isPushTrigger = type.AssemblyQualifiedNameNoTypeParams() == typeof(TriggerInput<string, string>).AssemblyQualifiedNameNoTypeParams();

            foreach (var propertyName in schema.properties.Keys)
            {
                var property = schema.properties[propertyName];

                if (isPushTrigger && propertyName == Constants.CALLBACK_URL_PROPERTY_NAME)
                {
                    #region Apply callback magic defaults

                    // Apply trigger magic defaults:
                    // "x-ms-scheduler-recommendation": "@accessKeys('default').primary.secretRunUri
                    schema.SetChildPropertyRequired(Constants.CALLBACK_URL_PROPERTY_NAME);

                    property.SetVisibility(VisibilityType.Internal);
                    property.SetSchedulerRecommendation(Constants.CALLBACK_URL_MAGIC_DEFAULT);

                    // This is what this will look like (pulled from HTTP Listener API Definition)
                    //
                    // "TriggerInput[TriggerPushParameters,TriggerOutputParameters]": {
                    //     "required": [            <-- SetChildPropertyRequired (on the parent model containing the callbackUrl property)
                    //       "callbackUrl"
                    // ],
                    // "type": "object",
                    // "properties": {
                    //   "callbackUrl": {            <-- SetSchedulerRecommendation (on the actual property)
                    //     "type": "string",
                    //     "x-ms-visibility": "internal",
                    //     "x-ms-scheduler-recommendation": "@accessKeys('default').primary.secretRunUri"
                    //   },

                    #endregion
                }

                // Apply friendly names and descriptions wherever possible
                // "x-ms-summary" - friendly name (applies to properties)
                // schema.properties["prop"].description - description (applies to parameters)

                var propertyInfo = type.GetRuntimeProperties().Where(p => p.Name == propertyName).FirstOrDefault();

                if (propertyInfo == null) return;

                var propertyMetadata = propertyInfo.GetCustomAttribute<MetadataAttribute>();

                if (propertyMetadata != null)
                {
                    property.SetVisibility(propertyMetadata.Visibility);
                    property.SetFriendlyNameAndDescription(propertyMetadata.FriendlyName, propertyMetadata.Description);
                }

            }
        }
開發者ID:ninocrudele,項目名稱:TRex,代碼行數:56,代碼來源:TRexSchemaFilter.cs

示例13: GetPublicInstanceProperties

 public IEnumerable<PropertyInfo> GetPublicInstanceProperties(Type mappedType)
 {
     if (mappedType == null)
     {
         throw new ArgumentNullException("mappedType");
     }
     return from p in mappedType.GetRuntimeProperties()
         where
             ((p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic) ||
              (p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic))
         select p;
 }
開發者ID:Reza1024,項目名稱:SQLite.Net-PCL,代碼行數:12,代碼來源:ReflectionServiceWP8.cs

示例14: GetProperty

        public static PropertyInfo GetProperty(Type sourceType, string propertyName)
        {
            var allProperties = sourceType.GetRuntimeProperties ();
            var property = allProperties.Where(
                mi => string.Equals(propertyName, mi.Name, StringComparison.Ordinal)).ToList();

            if (property.Count > 1)
            {
                throw new AmbiguousMatchException();
            }

            return property.FirstOrDefault();
        }
開發者ID:rid00z,項目名稱:JellyBeanTracker,代碼行數:13,代碼來源:ReflectionHelpers.cs

示例15: GetProperties

        public static IEnumerable<Property> GetProperties(Type type)
        {
            lock (PropertyCacheByType)
            {
                if (!PropertyCacheByType.ContainsKey(type))
                {
                    var properties = type.GetRuntimeProperties().Select(p => new Property(p, GetCustomAttributes(p))).ToList();
                    PropertyCacheByType[type] = properties;
                }

                return PropertyCacheByType[type];
            }
        }
開發者ID:tomstreet,項目名稱:NJsonSchema,代碼行數:13,代碼來源:ReflectionCache.cs


注:本文中的System.Type.GetRuntimeProperties方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。