Beispiel #1
0
        static void Main()
        {
            GenericList <int> integerList = new GenericList <int>();

            Console.WriteLine(integerList.Capacity); // 16
            Console.WriteLine(integerList.Count);    // 0

            integerList.Add(1);
            integerList.Add(2);
            integerList.InsertAt(1, 3);
            Console.WriteLine(integerList.Capacity);   // 16
            Console.WriteLine(integerList.Count);      // 3
            Console.WriteLine(integerList);            // {1, 3, 2}
            Console.WriteLine(integerList.IndexOf(1)); // 0
            Console.WriteLine(integerList.Exists(0));  // False
            Console.WriteLine(integerList.Exists(2));  // True

            integerList.RemoveAt(0);
            Console.WriteLine(integerList);                         // {3, 2}
            Console.WriteLine(integerList.IndexOf(1));              // -1
            Console.WriteLine(GenericList <int> .Min(integerList)); // 2
            Console.WriteLine(GenericList <int> .Max(integerList)); // 3

            integerList.InsertAt(12, 7);
            Console.WriteLine(integerList.Count); // 13
            Console.WriteLine(integerList);       // {3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7}

            System.Reflection.MemberInfo info = typeof(GenericList <>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
Beispiel #2
0
//      public static void Main()
//      {
//         MyMath mm = new MyMath();
//         Console.WriteLine( "Calling DoFunc(7). Result: {0}",
//            mm.DoFunc1( 7 ) );
//      }
        public static void Main()
        {
            MyMath mm = new MyMath();

            Console.WriteLine("Calling DoFunc(7). Result: {0}",
                              mm.DoFunc1(7));

            // get the member information and use it to
            // retrieve the custom attributes
            System.Reflection.MemberInfo inf = typeof(MyMath);
            object[] attributes;
            attributes =
                inf.GetCustomAttributes(
                    typeof(BugFixAttribute), false);

            // iterate through the attributes, retrieving the
            // properties
            foreach (Object attribute in attributes)
            {
                BugFixAttribute bfa = ( BugFixAttribute )attribute;
                Console.WriteLine("\nBugID: {0}", bfa.BugID);
                Console.WriteLine("Programmer: {0}", bfa.Programmer);
                Console.WriteLine("Date: {0}", bfa.Date);
                Console.WriteLine("Comment: {0}", bfa.Comment);
            }
        }
Beispiel #3
0
            static bool SignalFilter(System.Reflection.MemberInfo m, object filterCriteria)
            {
                string signame = (filterCriteria as string);

                object[] attrs = m.GetCustomAttributes(typeof(GLib.SignalAttribute), false);
                if (attrs.Length > 0)
                {
                    foreach (GLib.SignalAttribute a in attrs)
                    {
                        if (signame == a.CName)
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
                else
                {
                    /* this tries to match the names when no attibutes are present.
                     * It is only a fallback. */
                    signame = signame.ToLower().Replace("_", "");
                    string evname = m.Name.ToLower();
                    return(signame == evname);
                }
            }
Beispiel #4
0
        internal static string GetXmlName(System.Reflection.MemberInfo memberInfo)
        {
            var tmpXmlName    = memberInfo.Name;
            var tmpAttributes = memberInfo.GetCustomAttributes(true);

            var tmpXmlType = GetAttribute <System.Xml.Serialization.XmlTypeAttribute>(tmpAttributes);

            if (tmpXmlType != null)
            {
                tmpXmlName = tmpXmlType.TypeName;
            }

            var tmpXmlRoot = GetAttribute <System.Xml.Serialization.XmlRootAttribute>(tmpAttributes);

            if (tmpXmlRoot != null)
            {
                tmpXmlName = tmpXmlRoot.ElementName;
            }

            var tmpXmlArray = GetAttribute <System.Xml.Serialization.XmlArrayAttribute>(tmpAttributes);

            if (tmpXmlArray != null)
            {
                tmpXmlName = tmpXmlArray.ElementName;
            }

            var tmpXmlElement = GetAttribute <System.Xml.Serialization.XmlElementAttribute>(tmpAttributes);

            if (tmpXmlElement != null)
            {
                tmpXmlName = tmpXmlElement.ElementName;
            }

            return(tmpXmlName);
        }
        public override void DoTest()
        {
            Student stu1 = new Student()
            {
                ID = 1, Name = "Luffy", Age = 20, Sex = "男"
            };
            Student stu2 = new Student()
            {
                ID = 1, Name = "Nami", Age = -1, Sex = "女"
            };

            Console.WriteLine(stu1.ToString());
            Console.WriteLine(stu2.ToString());
            System.Reflection.MemberInfo info = typeof(Student);
            object[] attributes     = info.GetCustomAttributes(true);//特性名称
            var      classAttribute = (DzhTestAttribute)Attribute.GetCustomAttribute(info, typeof(DzhTestAttribute));

            Console.WriteLine(classAttribute.Name);
            Console.WriteLine(classAttribute.Date);
            Console.WriteLine(classAttribute.Describtion);
            for (int i = 0; i < attributes.Length; i++)
            {
                System.Console.WriteLine(attributes[i]);
            }
            Console.ReadKey();
        }
        public ServiceInstallerShell()
        {
            try
            {
                // InitializeComponent();
                this.serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
                this.serviceInstaller        = new System.ServiceProcess.ServiceInstaller();

                this.serviceProcessInstaller.Account  = System.ServiceProcess.ServiceAccount.LocalSystem;
                this.serviceProcessInstaller.Password = null;
                this.serviceProcessInstaller.Username = null;

                System.Reflection.MemberInfo info = GetType();
                var cus = info.GetCustomAttributes(typeof(ServiceAttribute), true);
                for (int i = 0; i < cus.Length; i++)
                {
                    var attribs = (ServiceAttribute)cus[i];
                    this.serviceInstaller.Description = attribs.Description;
                    this.serviceInstaller.DisplayName = attribs.DisplayName;
                    this.serviceInstaller.ServiceName = attribs.ServiceName;
                    break;
                }
                this.serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
                this.Installers.AddRange(new System.Configuration.Install.Installer[] {
                    this.serviceProcessInstaller,
                    this.serviceInstaller
                });
            }
            catch (Exception ex)
            {
                throw new Exception("my ServiceInstallerShell error!", ex);
            }
        }
        /// <summary>
        /// Common initialization
        /// </summary>
        /// <param name="member">MemberInfo/param>
        /// <param name="dataType">Type of property/field</param>
        private void CommonInit(System.Reflection.MemberInfo member, Type dataType)
        {
            MemberName   = member.Name;
            Type         = dataType;
            IsEnumerable = dataType.IsEnumerable();

            List <Attribute> attributes = new List <Attribute>();

            foreach (Attribute attribute in member.GetCustomAttributes(true))
            {
                attributes.Add(attribute);
            }

            CustomAttributes    = attributes;
            HasCustomAttributes = ((attributes != null) && (attributes.Count > 0));

            IsString = ((!IsEnumerable) && (Type == typeof(string)));

            Type underlyingType = Nullable.GetUnderlyingType(Type);

            IsNullable = (dataType == typeof(string)) || (underlyingType == typeof(string)) || (underlyingType != null);

            ActualTypeCode = Type.GetTypeCode(underlyingType ?? Type);

            if (IsEnumerable)
            {
                Type t   = dataType.GetGenericArguments()[0];
                Type t_u = Nullable.GetUnderlyingType(t);

                IsNullable         = (t_u != null);
                EnumerableType     = (t_u ?? t);
                EnumerableTypeCode = Type.GetTypeCode(EnumerableType);
            }
        }
                protected override JsonProperty CreateProperty(System.Reflection.MemberInfo member, MemberSerialization memberSerialization)
                {
                    var property = base.CreateProperty(member, memberSerialization);

                    property.ShouldSerialize = o => !member.GetCustomAttributes(true).OfType <ScriptIgnoreAttribute>().Any();
                    return(property);
                }
Beispiel #9
0
        public static string GetPropertyKey(System.Reflection.MemberInfo prop, EntityClassAttribute classAttribute)
        {
            string text = prop.Name;

            if (classAttribute != null && classAttribute.LowerCaseKey)
            {
                text = text.ToLower();
            }
            object[] customAttributes = prop.GetCustomAttributes(typeof(FieldAttribute), true);
            string   result;

            if (customAttributes == null)
            {
                result = text;
            }
            else
            {
                object[] array = customAttributes;
                for (int i = 0; i < array.Length; i++)
                {
                    object         obj            = array[i];
                    FieldAttribute fieldAttribute = obj as FieldAttribute;
                    if (fieldAttribute != null)
                    {
                        if (!string.IsNullOrEmpty(fieldAttribute.FieldName))
                        {
                            text = fieldAttribute.FieldName;
                        }
                    }
                }
                result = text;
            }
            return(result);
        }
Beispiel #10
0
            string MonoImpInfo(System.Reflection.MemberInfo mi, string itemtype, bool strlong)
            {
                if (quiet)
                {
                    return(string.Empty);
                }

                string s = string.Empty;

                object[] atts    = mi.GetCustomAttributes(true);
                int      todoctr = 0;

                foreach (object att in atts)
                {
                    if (att.GetType().Name == "MonoTODOAttribute")
                    {
                        todoctr++;
                    }
                }

                if (todoctr > 0)
                {
                    if (strlong)
                    {
                        s = "This " + itemtype + " is marked as being unfinished.<BR/>\n";
                    }
                    else
                    {
                        s = "Unfinished.";
                    }
                }

                return(s);
            }
Beispiel #11
0
        public static bool GuessIfUnityWillSerialize([NotNull] System.Reflection.MemberInfo memberInfo, [CanBeNull] object value)
        {
                        #if DONT_USE_ODIN_SERIALIZER
            if (memberInfo.IsStatic())
            {
                return(false);
            }
            var declaringType = memberInfo.DeclaringType;

            if (!(memberInfo is System.Reflection.FieldInfo))
            {
                return(false);
            }

            if (!declaringType.IsSerializable)
            {
                return(false);
            }

            if (declaringType.IsGenericType)
            {
                if (declaringType.IsGenericTypeDefinition)
                {
                    return(false);
                }
                return(declaringType.GetGenericTypeDefinition() == Types.List);
            }

            return(declaringType.IsSerializable && memberInfo is System.Reflection.FieldInfo);
                        #else
            var fieldType = memberInfo.DeclaringType;

            // Generic types are not supported, even with the SerializeReference attribute - with the exceptin of List<>.
            if (fieldType.IsGenericType)
            {
                return(fieldType.GetGenericTypeDefinition() == Types.List);
            }

                        #if UNITY_2019_3_OR_NEWER
            // With SerializeReference attribute Unity can serialize interface values if value does not derive from UnityEngine.Object
            if (memberInfo.GetCustomAttributes(typeof(SerializeReference), false).Length > 0)
            {
                return(value == null || !Types.UnityObject.IsAssignableFrom(value.GetType()));
            }
                        #endif

            if (fieldType.IsAbstract)
            {
                return(false);
            }

            if (fieldType == Types.SystemObject)
            {
                return(false);
            }

            return(UnitySerializationUtility.GuessIfUnityWillSerialize(memberInfo));
                        #endif
        }
Beispiel #12
0
        private bool _isNullable;                              // = false;

        internal void GetDecorations(System.Reflection.MemberInfo memberInfo)
        {
            object[] attrs = memberInfo.GetCustomAttributes(true);
            for (int i = 0; i < attrs.Length; i++)
            {
                Add(attrs[i]);
            }
        }
Beispiel #13
0
 static void Main(string[] args)
 {
     System.Reflection.MemberInfo point = typeof(Point3D);
     Console.WriteLine("Attributes for : " + point.Name);
     foreach (object attribute in point.GetCustomAttributes(true))
     {
         Console.WriteLine(attribute);
     }
 }
        private bool _isNullable;                              // = false;

        internal void GetDecorations(System.Reflection.MemberInfo memberInfo)
        {
            var attrs = memberInfo.GetCustomAttributes(true);

            foreach (var attr in attrs)
            {
                Add(attr);
            }
        }
Beispiel #15
0
 static void Main(string[] args)
 {
     System.Reflection.MemberInfo info = typeof(MyClass);
     object[] attritubes = info.GetCustomAttributes(true);
     for (int idx = 0; idx < attritubes.Length; ++idx)
     {
         Console.WriteLine(attritubes[idx]);
     }
 }
Beispiel #16
0
 public void PrintValue()
 {
     System.Reflection.MemberInfo info = typeof(Myclass);
     object[] attributes = info.GetCustomAttributes(true);
     for (int i = 0; i < attributes.Length; i++)
     {
         Console.WriteLine(attributes[i]);
     }
 }
Beispiel #17
0
        public static K CreateMonoSingleton <K>() where K : MonoBehaviour, ISingleton
        {
            if (IsApplicationQuit)
            {
                return(null);
            }

            K instance = null;

            if (instance == null && !IsApplicationQuit)
            {
                instance = GameObject.FindObjectOfType(typeof(K)) as K;
                if (instance == null)
                {
                    System.Reflection.MemberInfo info = typeof(K);
                    object[] attributes = info.GetCustomAttributes(true);
                    for (int i = 0; i < attributes.Length; ++i)
                    {
                        MonoSingletonAttribute defineAttri = attributes[i] as MonoSingletonAttribute;
                        if (defineAttri == null)
                        {
                            continue;
                        }
                        instance = CreateComponentOnGameObject <K>(defineAttri.AbsolutePath, true);
                        break;
                    }

                    if (instance == null)
                    {
                        GameObject obj = new GameObject("Singleton of " + typeof(K).Name);
                        UnityEngine.Object.DontDestroyOnLoad(obj);
                        instance = obj.AddComponent <K>();
                    }
                }
                else
                {
                    System.Reflection.MemberInfo info = typeof(K);
                    object[] attributes = info.GetCustomAttributes(true);
                    for (int i = 0; i < attributes.Length; ++i)
                    {
                        MonoSingletonAttribute defineAttri = attributes[i] as MonoSingletonAttribute;
                        if (defineAttri == null)
                        {
                            continue;
                        }
                        instance.transform.SetParent(MoveGameObjectToPath(defineAttri.AbsolutePath, true).transform);
                        instance.gameObject.name = defineAttri.AbsolutePath.Split('/').Last();
                        break;
                    }
                }

                instance.OnSingletonInit();
            }

            return(instance);
        }
Beispiel #18
0
 /// <summary>
 /// 启动执行
 /// </summary>
 public void HelperRun()
 {
     System.Reflection.MemberInfo info = typeof(ReflectionHelper);
     object[] attributes = info.GetCustomAttributes(true);
     for (int index = 0; index < attributes.Length; index++)
     {
         Console.WriteLine(attributes[index]);
     }
     Console.ReadKey();
 }
Beispiel #19
0
        private void MapValuesFromJobDetail(IJobDetail jobDetail)
        {
            JobName          = jobDetail.Key.Name;
            JobGroup         = jobDetail.Key.Group;
            FireUrl          = "/FireJob/" + JobGroup + "/" + JobName;
            Description      = jobDetail.Description;
            RequestsRecovery = jobDetail.RequestsRecovery;
            StoreDurable     = jobDetail.Durable;
            JobType          = jobDetail.JobType.ToString();

            System.Reflection.MemberInfo inf       = jobDetail.JobType;
            object[] concurrentExecutionAttributes = inf.GetCustomAttributes(typeof(DisallowConcurrentExecutionAttribute), true);
            object[] persisJobDataAttributes       = inf.GetCustomAttributes(typeof(PersistJobDataAfterExecutionAttribute), true);

            ConcurrentExecutionAllowed   = concurrentExecutionAttributes.Length <= 0;
            PersistJobDataAfterExecution = persisJobDataAttributes.Length > 0;

            JobDataMap = jobDetail.JobDataMap;
        }
Beispiel #20
0
 static void Main(string[] args)
 {
     System.Reflection.MemberInfo info = typeof(MyClass);
     object[] attributes = info.GetCustomAttributes(true);
     for (int i = 0; i < attributes.Length; i++)
     {
         System.Console.WriteLine(attributes[i]);
     }
     Console.ReadKey();
 }
Beispiel #21
0
 /// <summary>
 /// Test is a member is available.
 /// </summary>
 /// <param name="member">The member to test for availability.</param>
 /// <returns>The availability of the member.</returns>
 public static FunctionAvailability GetAvailability(System.Reflection.MemberInfo member)
 {
     foreach (var att in member.GetCustomAttributes(false))
     {
         if (att is AvailableSinceAttribute)
         {
             return(Util.IsCapableOfRunning((att as AvailableSinceAttribute).AvailableSince) ? FunctionAvailability.Avaliable : FunctionAvailability.NotSupported);
         }
     }
     return(FunctionAvailability.Unknown);
 }
Beispiel #22
0
        private static T GetAttribute <T>(System.Reflection.MemberInfo memberInfo, bool includeInherited)
            where T : System.Attribute
        {
            object[] objArr = memberInfo.GetCustomAttributes(typeof(T), includeInherited);
            if (objArr.Length == 1)
            {
                return((T)objArr[0]);
            }

            return(null);
        }
Beispiel #23
0
 internal static Version GetRequiredVersion(System.Reflection.MemberInfo member)
 {
     foreach (var att in member.GetCustomAttributes(false))
     {
         if (att is AvailableSinceAttribute)
         {
             return((att as AvailableSinceAttribute).AvailableSince);
         }
     }
     return(new Version()); // 0.0
 }
Beispiel #24
0
 public string GetCommandName()
 {
     System.Reflection.MemberInfo info = this.GetType();
     object[] attributes = info.GetCustomAttributes(true);
     if (attributes.Length == 1)
     {
         CommandName attr = attributes[0] as CommandName;
         return(attr.Name);
     }
     return("Unrecognized");
 }
Beispiel #25
0
        private static string GetMemberDescription(System.Reflection.MemberInfo memberInfo)
        {
            string result = null;
            DescriptionAttribute descriptionAttribute = memberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault <object>() as DescriptionAttribute;

            if (descriptionAttribute != null)
            {
                result = descriptionAttribute.Description;
            }
            return(result);
        }
Beispiel #26
0
 /// <summary>
 /// Get permission for a member.
 /// </summary>
 /// <param name="member">The member to get permission for.</param>
 /// <returns>The permission of the member, or empty string if no permission attribute is avaliable.</returns>
 public static string GetPermission(System.Reflection.MemberInfo member)
 {
     foreach (var att in member.GetCustomAttributes(false))
     {
         if (att is RequiredPermissionAttribute)
         {
             return((att as RequiredPermissionAttribute).PermissionString);
         }
     }
     return(string.Empty);
 }
 public static bool IsSettingStorageAttributeSet(System.Reflection.MemberInfo prop, StorageTarget targetIn)
 {
     SettingStorageAttribute[] attr = (SettingStorageAttribute[])prop.GetCustomAttributes(typeof(SettingStorageAttribute), false);
     if (attr != null)
     {
         if (attr.Length > 0)
         {
             return(attr[0].Target == targetIn);
         }
     }
     return(false);
 }
Beispiel #28
0
        public static bool GetAttributeNames(System.Reflection.MemberInfo check, Type attribute)
        {
            bool result = false;

            var isAttribute = check.GetCustomAttributes(attribute, false);

            if (isAttribute.Length > 0)
            {
                result = true;
            }
            return(result);
        }
Beispiel #29
0
        bool CheckDisplayNameAttribute <TAttribute>(System.Reflection.MemberInfo member, Func <TAttribute, string> accessor, ref string displayName)
            where TAttribute : Attribute
        {
            var displayAttributes = member.GetCustomAttributes(typeof(TAttribute), true);

            if (displayAttributes.Length > 0)
            {
                displayName = accessor((TAttribute)displayAttributes[0]);
                return(true);
            }
            return(false);
        }
Beispiel #30
0
        public static TValue GetAttributeValue <TAttribute, TValue>(System.Reflection.MemberInfo mi
                                                                    , System.Func <TAttribute, TValue> getValue)
            where TAttribute : System.Attribute
        {
            TAttribute[] attributes = (TAttribute[])(object)mi.GetCustomAttributes(typeof(TAttribute), false);

            if (attributes == null)
            {
                return(default(TValue));
            }

            return(getValue(attributes[0]));
        }