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


C# Type.IsDefined方法代码示例

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


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

示例1: BuildTable

 private LitTable BuildTable(Type type)
 {
     LitTable table = null;
     if (!type.IsDefined(typeof(TableAttribute), false))
     {
         if (!type.IsDefined(typeof(SPResultAttribute), false))
             throw new LightException("no TableAttribute or SPResultAttribute found on " + type.FullName);
         else
             table = new LitTable(type, null, null);
     }
     else
     {
         TableAttribute tableAttr = (TableAttribute)type.GetCustomAttributes(typeof(TableAttribute), false)[0];
         string name = tableAttr.Name;
         string schema = tableAttr.Schema;
         if (name == null || name.Length == 0)
             name = type.Name;
         table = new LitTable(type, name, schema);
     }
     FindInherited(type, table);
     ProcessFields(type, table);
     ProcessProperties(type, table);
     ProcessMethods(type, table);
     return table;
 }
开发者ID:priceLiu,项目名称:Enterprise.Company,代码行数:25,代码来源:LitTableFactory.cs

示例2: GetConversionCost

        /// <inheritdoc />
        public ConversionCost GetConversionCost(Type sourceType, Type targetType, IConverter elementConverter)
        {
            if (typeof(XPathNavigator).IsAssignableFrom(sourceType)
                && targetType.IsDefined(typeof(XmlTypeAttribute), true)
                && targetType.IsDefined(typeof(XmlRootAttribute), true))
                return ConversionCost.Typical;

            return ConversionCost.Invalid;
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:10,代码来源:XPathNavigatorToXmlSerializableTypeConversionRule.cs

示例3: DrawAndGetNewValue

 public object DrawAndGetNewValue(Type memberType, string memberName, object value, Entity entity, int index, IComponent component)
 {
     if(memberType.IsDefined(typeof(FlagsAttribute), false)) {
         return EditorGUILayout.EnumMaskField(memberName, (Enum)value);
     }
     return EditorGUILayout.EnumPopup(memberName, (Enum)value);
 }
开发者ID:sschmid,项目名称:Entitas-CSharp,代码行数:7,代码来源:EnumTypeDrawer.cs

示例4: GetLifecycle

        /// <summary>
        /// 获取生命周期
        /// </summary>
        public static Lifecycle GetLifecycle(Type type)
        {
            if (!type.IsDefined(typeof(LifeCycleAttribute), false))
                return Lifecycle.Singleton;

            return type.GetCustomAttribute<LifeCycleAttribute>(false).Lifetime;
        }
开发者ID:imyounghan,项目名称:thinklib,代码行数:10,代码来源:LifeCycleAttribute.cs

示例5: AddTypeToLookupTables

        private void AddTypeToLookupTables(Type type)
        {
            if (type == null)
            {
                return;
            }

            // we've seen it already
            if (_typeByName.ContainsKey(type.Name))
            {
                return;
            }

            // look this Type up by name
            _typeByName[type.Name] = type;

            if (!type.IsDefined(typeof(JsonApiResourceTypeAttribute), true))
            {
                return;
            }

            var attribute =
                type.GetCustomAttributes(typeof(JsonApiResourceTypeAttribute), true).FirstOrDefault() as JsonApiResourceTypeAttribute;

            if (attribute != null)
            {
                _typeByJsonApiResourceTypeName[attribute.JsonApiResourceTypeName] = type;
            }
        }
开发者ID:RafaelFOliveira,项目名称:JsonApiNet,代码行数:29,代码来源:ReflectingTypeResolver.cs

示例6: Handle

 /// <summary>
 /// Handles the specified Type depending on the scanning strategy
 /// of the <see cref="TypeConfiguration"/>.
 /// </summary>
 /// <param name="type">Type to handle.</param>
 internal void Handle( Type type )
 {
     switch ( ScanningStrategy )
     {
         case ScanFor.TypesThatAreDecoratedWithThisAttribute:
             if ( type.IsDefined( Type, true ) )
             {
                 Action( type );
             }
             break;
         case ScanFor.TypesThatImplementThisInterface:
             if ( Type.IsAssignableFrom( type ) && type.IsInterface == false )
             {
                 Action( type );
             }
             break;
         case ScanFor.TypesThatInheritFromThisAbstractClass:
             if ( Type.IsAssignableFrom( type ) && type.IsAbstract == false )
             {
                 Action( type );
             }
             break;
         case ScanFor.TypesThatInheritFromThisClass:
             if ( Type.IsAssignableFrom( type ) && type != Type )
             {
                 Action( type );
             }
             break;
         default:
             Action( type );
             break;
     }
 }
开发者ID:randyburden,项目名称:FluentTypeScanner,代码行数:38,代码来源:TypeConfiguration.cs

示例7: PortableEnum

        /// <summary>
        /// Constructor from an enumerated type
        /// </summary>
        /// <param name="enumType">A type representing an existing enumeration</param>
        /// <exception cref="System.ArgumentException">Throw if the type if not an enumerated type</exception>
        public PortableEnum(Type enumType)
        {
            if (!enumType.IsEnum)
            {
                throw new ArgumentException("Parameter is not an enumerated type");
            }

            _entries = new Dictionary<string, long>();
            string[] names = Enum.GetNames(enumType);
            Array values = Enum.GetValues(enumType);

            for (int i = 0; i < names.Length; ++i)
            {
                long v = (long)Convert.ChangeType(values.GetValue(i), typeof(long));

                _entries.Add(names[i], v);
            }

            if (enumType.IsDefined(typeof(FlagsAttribute), false))
            {
                _isFlags = true;
            }
            else
            {
                _isFlags = false;
            }

            _value = 0;
            _name = enumType.Name;
        }
开发者ID:michyer,项目名称:canape,代码行数:35,代码来源:EnumDataValue.cs

示例8: CreateMemberSetters

 private MemberSetter[] CreateMemberSetters(Type type)
 {
     var selfMembers = type
         .GetProperties(bindingFlags)
         .Where(m => m.CanWrite)
         .Union(type.GetFields(bindingFlags).Cast<MemberInfo>())
         .Where(m => m.IsDefined(typeof (InjectAttribute), true))
         .ToArray();
     MemberSetter[] baseSetters = null;
     if (!type.IsDefined<FrameworkBoundaryAttribute>(false))
     {
         var baseType = type.BaseType;
         if (baseType != typeof (object))
             baseSetters = GetMembers(baseType);
     }
     if (selfMembers.Length == 0 && baseSetters != null)
         return baseSetters;
     var baseMembersCount = baseSetters == null ? 0 : baseSetters.Length;
     var result = new MemberSetter[selfMembers.Length + baseMembersCount];
     if (baseMembersCount > 0)
         Array.Copy(baseSetters, 0, result, 0, baseMembersCount);
     for (var i = 0; i < selfMembers.Length; i++)
     {
         var member = selfMembers[i];
         var resultIndex = i + baseMembersCount;
         result[resultIndex].member = member;
         result[resultIndex].setter = MemberAccessorsFactory.GetSetter(member);
     }
     return result;
 }
开发者ID:undeadcat,项目名称:simple-container,代码行数:30,代码来源:MemberInjectionsProvider.cs

示例9: FindInherited

 private void FindInherited(Type type, LitTable table)
 {
     if (type.IsDefined(typeof(MapAttribute), false))
     {
         object[] attrs = type.GetCustomAttributes(typeof(MapAttribute), false);
         foreach (MapAttribute attr in attrs)
         {
             IDataBridge data = null;
             BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
             MemberInfo member = type.GetProperty(attr.Field, flags);
             if (member != null)
             {
                 data = new PropertyBridge((PropertyInfo)member);
             }
             else
             {
                 member = type.GetField(attr.Field, flags);
                 if (member != null)
                     data = new FieldBridge((FieldInfo)member);
                 else
                     throw new LightException("member " + attr.Field + " not found in class " + type.Name);
             }
             if (attr.Name == null || attr.Name.Length == 0)
                 attr.Name = member.Name;
             SqlColumn column = new SqlColumn(table, attr.Name, data);
             if (attr.Alias == null || attr.Alias.Length == 0)
                 column.Alias = attr.Field;
             else
                 column.Alias = attr.Alias;
             column.IsID = attr.ID;
             column.IsPK = attr.PK;
             table.Add(column);
         }
     }
 }
开发者ID:priceLiu,项目名称:Enterprise.Company,代码行数:35,代码来源:LitTableFactory.cs

示例10: ProcessType

 protected void ProcessType(Type type)
 {
     if (type.IsDefined(typeof(MapClassAttribute), false))
     {
         m_classDescriptors.Add(CreateMapping(type));
     }
 }
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:7,代码来源:SingleTypeMappingDescriptorProvider.cs

示例11: ReadJson

        /// <inheritdoc/>
        public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            if (HandleNullableTypes(ref objectType) && reader.TokenType == JsonToken.Null)
                return null;

            if (reader.TokenType == JsonToken.String || !objectType.IsDefined(typeof(FlagsAttribute), false))
            {
                return Enum.Parse(objectType, serializer.Deserialize<String>(reader));
            }
            else
            {
                var enumNames = (String[])serializer.Deserialize(reader, typeof(String[]));
                if (enumNames == null)
                    throw new JsonReaderException(NucleusStrings.JsonValueCannotBeNull);

                var enumValue = 0ul;

                for (int i = 0; i < enumNames.Length; i++)
                {
                    enumValue |= Convert.ToUInt64(Enum.Parse(objectType, enumNames[i]));
                }

                return Enum.ToObject(objectType, enumValue);
            }
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:26,代码来源:NucleusEnumJsonConverter.cs

示例12: CreateViewModelConfig

        public ViewModelConfig CreateViewModelConfig(Type type)
        {
            if (!type.IsBaseObject() && !type.IsDefined(typeof(ComplexTypeAttribute))) return null;

            string serviceName = "";

            if (type.IsBaseObject())
            {
                if (type.IsAssignableFrom(typeof(HCategory)))
                    serviceName = typeof(IBaseCategoryService<>).GetTypeName();
                else if (type.IsAssignableFrom(typeof(ICategorizedItem)))
                    serviceName = typeof(IBaseCategorizedItemService<>).GetTypeName();
                else
                    serviceName = typeof(IBaseObjectService<>).GetTypeName();
            }

            return new ViewModelConfig(
                mnemonic: type.GetTypeName(),
                entity: type.GetTypeName(),
                listView: new ListView(),
                detailView: new DetailView(),
                lookupProperty:
                    type.IsBaseObject()
                        ? (type.GetProperty("Title") ?? type.GetProperty("Name") ?? type.GetProperty("ID")).Name
                        : "",
                service: serviceName);
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:27,代码来源:ViewModelConfigService.cs

示例13: IsCompilerGenerated

        private bool IsCompilerGenerated(Type t)
        {
            if (t == null)
                return false;

            return t.IsDefined(typeof(CompilerGeneratedAttribute), false) || IsCompilerGenerated(t.DeclaringType);
        }
开发者ID:distantcam,项目名称:conventional,代码行数:7,代码来源:IgnoreCompilerTypesFilter.cs

示例14: getGroups

        private static void getGroups(string fieldName, Type type, object original, object translation,
            NumberSystem originalNumSys, NumberSystem translationNumSys, Dictionary<object, TranslationGroup> dic,
            ref TranslationGroup ungrouped, IEnumerable<object> classGroups, string path)
        {
            if (!type.IsDefined<LingoStringClassAttribute>(true))
            {
                if (fieldName == null)
                    throw new ArgumentException(@"Type ""{0}"" must be marked with the [LingoStringClass] attribute.".Fmt(type.FullName), "type");
                else
                    throw new ArgumentException(@"Field ""{0}.{1}"" must either be marked with the [LingoIgnore] attribute, or be of type TrString, TrStringNumbers, or a type with the [LingoStringClass] attribute.".Fmt(type.FullName, fieldName), "type");
            }

            var thisClassGroups = type.GetCustomAttributes(true).OfType<LingoInGroupAttribute>().Select(attr => attr.Group);
            if (classGroups != null)
                thisClassGroups = thisClassGroups.Concat(classGroups);

            foreach (var f in type.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                if (f.FieldType == typeof(TrString) || f.FieldType == typeof(TrStringNum))
                {
                    string notes = f.GetCustomAttributes<LingoNotesAttribute>().Select(lna => lna.Notes).FirstOrDefault();
                    var trInfo = f.FieldType == typeof(TrString)
                        ? (TranslationInfo) new TrStringInfo
                        {
                            Label = path + f.Name,
                            Notes = notes,
                            NewOriginal = ((TrString) f.GetValue(original)).Translation,
                            TranslationTr = (TrString) f.GetValue(translation)
                        }
                        : (TranslationInfo) new TrStringNumInfo((TrStringNum) f.GetValue(original), (TrStringNum) f.GetValue(translation), originalNumSys, translationNumSys)
                        {
                            Label = path + f.Name,
                            Notes = notes
                        };

                    var groups = f.GetCustomAttributes<LingoInGroupAttribute>().Select(attr => attr.Group).Concat(thisClassGroups);
                    if (!groups.Any())
                    {
                        if (ungrouped == null)
                            ungrouped = new TranslationGroup { Label = "Ungrouped strings", Notes = "This group contains strings not found in any other group." };
                        ungrouped.Infos.Add(trInfo);
                    }
                    else
                    {
                        foreach (var group in groups)
                        {
                            TranslationGroup grp;
                            if (!dic.TryGetValue(group, out grp))
                            {
                                grp = createGroup(group);
                                dic[group] = grp;
                            }
                            grp.Infos.Add(trInfo);
                        }
                    }
                }
                else if (!f.IsDefined<LingoIgnoreAttribute>(true))
                    getGroups(f.Name, f.FieldType, f.GetValue(original), f.GetValue(translation), originalNumSys, translationNumSys, dic, ref ungrouped, thisClassGroups, path + f.Name + " / ");
            }
        }
开发者ID:caesay,项目名称:RT.Util,代码行数:60,代码来源:TranslationDialog.cs

示例15: AllowsUnauthorized

        private Boolean AllowsUnauthorized(Type authorizedControllerType, MethodInfo method)
        {
            if (method.IsDefined(typeof(AuthorizeAttribute), false)) return false;
            if (method.IsDefined(typeof(AllowAnonymousAttribute), false)) return true;
            if (method.IsDefined(typeof(AllowUnauthorizedAttribute), false)) return true;

            while (authorizedControllerType != typeof(Controller))
            {
                if (authorizedControllerType.IsDefined(typeof(AuthorizeAttribute), false)) return false;
                if (authorizedControllerType.IsDefined(typeof(AllowAnonymousAttribute), false)) return true;
                if (authorizedControllerType.IsDefined(typeof(AllowUnauthorizedAttribute), false)) return true;

                authorizedControllerType = authorizedControllerType.BaseType;
            }

            return true;
        }
开发者ID:vothlizard,项目名称:MVC.Template,代码行数:17,代码来源:AuthorizationProvider.cs


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