示例#1
0
        // note : originally input deltaTime when iterating. Faster, but issues is that deltaTime might differ when -creating -the invocations and when executing them. Now fetches the current deltaTime when creating new flows, then use a cached deltaTime when iterating.
        public static void LinkDeltaTimeProperties(System.Reflection.PropertyInfo deltaTimeProperty, System.Reflection.PropertyInfo unscaledDeltaTimeProperty)
        {
            var del = deltaTimeProperty.GetGetMethod().CreateDelegate(typeof(Func <float>));

            _getDeltaTime = (Func <float>)del;

            del = deltaTimeProperty.GetGetMethod().CreateDelegate(typeof(Func <float>));
            _getUnscaledDeltaTime = (Func <float>)del;
        }
示例#2
0
 public IMethod GetGetMethod()
 {
     System.Reflection.MethodInfo getter = _property.GetGetMethod(true);
     if (null != getter)
     {
         return(_typeSystemServices.Map(getter));
     }
     return(null);
 }
示例#3
0
        private void parentUserCtrl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            texOneProp = null;
            texTwoProp = null;
            if (e.OldValue != null)
            {
                if (weatherCtrlProp != null)
                {
                    object weatherCtrl = weatherCtrlProp.Invoke(e.OldValue, null);
                    if (weatherCtrl is INotifyPropertyChanged)
                    {
                        ((INotifyPropertyChanged)weatherCtrl).PropertyChanged -= TestTextureChanged;
                    }
                }
                weatherCtrlProp = null;
            }
            if (e.NewValue != null)
            {
                object weatherCtrl = null;
                System.Reflection.PropertyInfo weatherTestProp = e.NewValue.GetType().GetProperty("WeatherTest");
                if (weatherTestProp != null)
                {
                    weatherCtrlProp = weatherTestProp.GetGetMethod();
                    weatherCtrl     = weatherCtrlProp.Invoke(e.NewValue, null);
                    if (weatherCtrl is INotifyPropertyChanged)
                    {
                        System.Reflection.PropertyInfo p = null;
                        p = weatherCtrl.GetType().GetProperty("TextureOne");
                        if (p != null)
                        {
                            texOneProp = p.GetGetMethod();
                        }
                        p = weatherCtrl.GetType().GetProperty("TextureTwo");
                        if (p != null)
                        {
                            texTwoProp = p.GetGetMethod();
                        }
                        ((INotifyPropertyChanged)weatherCtrl).PropertyChanged += TestTextureChanged;
                    }
                }

                TestTextureChanged(weatherCtrl, new PropertyChangedEventArgs("TextureOne"));
                TestTextureChanged(weatherCtrl, new PropertyChangedEventArgs("TextureTwo"));
            }

            if (texOneProp == null)
            {
                testImgCtrl.Source = null;
                Debug.WriteLine("Cannot bind to WeatherTest.TextureOne property");
            }
            if (texTwoProp == null)
            {
                testImgEffect.Input2 = null;
                Debug.WriteLine("Cannot bind to WeatherTest.TextureTwo property");
            }
        }
        public static string AggregateWhere <T>(List <T> Array, string IfMethod, string ValueMethod, char?split)
#endif
        {
            Type type = typeof(T);

            System.Reflection.PropertyInfo propertyValue = type.GetProperty(ValueMethod);
            System.Reflection.PropertyInfo propertyIf    = type.GetProperty(IfMethod);
            System.Reflection.MethodInfo   methodValue   = propertyValue.GetGetMethod();
            System.Reflection.MethodInfo   methodIf      = propertyIf.GetGetMethod();
            string stmp = string.Empty;

            foreach (T item in Array)
            {
                GetValue <string> getValue   = (GetValue <string>)Delegate.CreateDelegate(typeof(GetValue <string>), item, methodValue);
                GetValue <bool>   getBoolean = (GetValue <bool>)Delegate.CreateDelegate(typeof(GetValue <bool>), item, methodIf);

                if (getBoolean())
                {
                    if (split.HasValue && stmp.Length > 0)
                    {
                        stmp += split.Value;
                    }

                    stmp += getValue();
                }
            }
            return(stmp);
        }
示例#5
0
        public JsPropertyDefinition(string name, System.Reflection.PropertyInfo propInfo)
            : base(name, JsMemberKind.Property)
        {
            this.propInfo = propInfo;
#if NET20
            var getter = propInfo.GetGetMethod(true);
            if (getter != null)
            {
                this.GetterMethod = new JsPropertyGetDefinition(name, getter);
            }
            var setter = propInfo.GetSetMethod(true);
            if (setter != null)
            {
                this.SetterMethod = new JsPropertySetDefinition(name, setter);
            }
#else
            var getter = propInfo.GetMethod;
            if (getter != null)
            {
                this.GetterMethod = new JsPropertyGetDefinition(name, getter);
            }
            var setter = propInfo.SetMethod;
            if (setter != null)
            {
                this.SetterMethod = new JsPropertySetDefinition(name, setter);
            }
#endif
        }
示例#6
0
        private DictionaryInfo(TypeInfo typeInfo, System.Reflection.PropertyInfo info, TypeInfo keyType, TypeInfo valueType)
            : base(typeInfo, info, keyType, valueType)
        {
            this.info = info;

            this.callTryGetValue = new Lazy <TryGetValueDelegate>(() =>
            {
                System.Reflection.MethodInfo tryGetMethod = typeInfo.Type.GetMethod("TryGetValue");
                if (tryGetMethod == null)
                {
                    return(null);
                }

                ParameterExpression targetParam   = Expression.Parameter(typeof(object), null);
                ParameterExpression keyParam      = Expression.Parameter(typeof(object), null);
                ParameterExpression outValueParam = Expression.Parameter(typeof(object).MakeByRefType(), null);
                Expression castTarget             = ReflectionUtility.Convert(targetParam, typeInfo);
                Expression castKey    = ReflectionUtility.Convert(keyParam, keyType);
                Expression callTryGet = Expression.Call(castTarget, tryGetMethod, castKey, outValueParam);

                return(ReflectionUtility.CompileLambda <TryGetValueDelegate>(callTryGet, targetParam, keyParam, outValueParam));
            });

            this.callGet = new Lazy <Func <object, object, object> >(() =>
            {
                System.Reflection.MethodInfo getMethod = info.GetGetMethod(nonPublic: false);
                if (getMethod == null)
                {
                    return(null);
                }

                ParameterExpression targetParam = Expression.Parameter(typeof(object), null);
                ParameterExpression keyParam    = Expression.Parameter(typeof(object), null);
                Expression castTarget           = ReflectionUtility.Convert(targetParam, typeInfo);
                Expression castKey = ReflectionUtility.Convert(keyParam, keyType);
                Expression callGet = Expression.Call(castTarget, getMethod, castKey);

                return(ReflectionUtility.CompileLambda <Func <object, object, object> >(callGet, targetParam, keyParam));
            });

            this.callSet = new Lazy <Action <object, object, object> >(() =>
            {
                System.Reflection.MethodInfo setMethod = info.GetSetMethod(nonPublic: false);
                if (setMethod == null)
                {
                    return(null);
                }

                ParameterExpression targetParam = Expression.Parameter(typeof(object), null);
                ParameterExpression keyParam    = Expression.Parameter(typeof(object), null);
                ParameterExpression valueParam  = Expression.Parameter(typeof(object), null);
                Expression castTarget           = ReflectionUtility.Convert(targetParam, typeInfo);
                Expression castKey   = ReflectionUtility.Convert(keyParam, keyType);
                Expression castValue = ReflectionUtility.Convert(valueParam, valueType);
                Expression callSet   = Expression.Call(castTarget, setMethod, castKey, castValue);

                return(ReflectionUtility.CompileLambda <Action <object, object, object> >(callSet, targetParam, keyParam, valueParam));
            });
        }
        /// <summary>
        /// Initializes the internal structures from values specified in the .config files
        /// </summary>
        /// <param name="providerName">Unique name used to refer to this instance of SqlServerStorageProvider</param>
        /// <param name="attrs">Parameters stored in the .config files</param>
        public override void Initialize(string providerName, NameValueCollection attrs)
        {
            this._name = providerName;

            //Get parameters from attrs
            _connectionString      = attrs["ConnectionString"];
            _tableName             = safeName(attrs["TableName"]);
            _dataColumnName        = safeName(attrs["DataColumnName"]);
            _partialFlagColumnName = safeName(attrs["PartialFlagColumnName"]);
            _fileNameColumnName    = safeName(attrs["FileNameColumnName"]);
            _MIMETypeColumnName    = safeName(attrs["MIMETypeColumnName"]);

            _createProcedure    = attrs["CreateProcedure"];
            _openProcedure      = attrs["OpenProcedure"];
            _writeProcedure     = attrs["WriteProcedure"];
            _readProcedure      = attrs["ReadProcedure"];
            _cleanupProcedure   = attrs["CleanupProcedure"];
            _renameProcedure    = attrs["RenameProcedure"];
            _storeHashProcedure = attrs["StoreHashProcedure"];
            _deleteProcedure    = attrs["DeleteProcedure"];

            _hashAlgorithm  = attrs["HashAlgorithm"];
            _hashColumnName = safeName(attrs["HashColumnName"]);


            //In .net v2.0 there is a nice ConfigurationManager and centralized ConnectionStrings. Use it if "ConnectionName" is specified
            if (System.Environment.Version.Major >= 2 && attrs["ConnectionName"] != null && attrs["ConnectionName"].Length > 0)
            {
                _connectionName = attrs["ConnectionName"];
                // Use reflection to do:
                //   _connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[_connectionName].ConnectionString;
                // so we don't need a special 2.0 version of the assembly.
                string configAssembly = "System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL";
                Type   configManager  = Type.GetType("System.Configuration.ConfigurationManager, " + configAssembly, true);
                System.Reflection.PropertyInfo connStringsPropInfo = configManager.GetProperty("ConnectionStrings");
                object connStringSettingCollection = connStringsPropInfo.GetGetMethod().Invoke(null, null);
                System.Reflection.BindingFlags instanceGetPropBindingFlags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Public;
                object connStringSettings = Type.GetType("System.Configuration.ConnectionStringSettingsCollection, " + configAssembly)
                                            .InvokeMember("", instanceGetPropBindingFlags, null, connStringSettingCollection, new object[] { _connectionName });
                _connectionString = (string)Type.GetType("System.Configuration.ConnectionStringSettings, " + configAssembly)
                                    .InvokeMember("ConnectionString", instanceGetPropBindingFlags, null, connStringSettings, null);
            }

            //Make sure we have at least a connenction string, a table name and a dataColumnName. The rest is optional
            string error = string.Empty;

            if (_connectionString == null)
            {
                error = "No ConnectionString specified";
            }
            if (_createProcedure == null && (_tableName == null || _dataColumnName == null))
            {
                error += (error.Length > 0 ? "; " : string.Empty) + "Either CreatorProcedure or TableName/DataColumnName mut be specified";
            }
            if (error.Length > 0)
            {
                throw new System.Xml.XmlException("Missing attribute: " + error);
            }
        }
 public void System_PropertyInfo_is_wrapped_by_Routine_PropertyInfo()
 {
     Assert.AreEqual(propertyInfo.Name, testing.Name);
     Assert.AreEqual(propertyInfo.GetGetMethod()?.Name, testing.GetGetMethod().Name);
     Assert.AreEqual(propertyInfo.GetSetMethod()?.Name, testing.GetSetMethod().Name);
     Assert.AreSame(propertyInfo.DeclaringType, testing.DeclaringType.GetActualType());
     Assert.AreSame(propertyInfo.ReflectedType, testing.ReflectedType.GetActualType());
     Assert.AreSame(propertyInfo.PropertyType, testing.PropertyType.GetActualType());
 }
示例#9
0
 System.Reflection.MethodInfo GetAccessor()
 {
     System.Reflection.MethodInfo mi = _property.GetGetMethod(true);
     if (null != mi)
     {
         return(mi);
     }
     return(_property.GetSetMethod(true)
            );
 }
示例#10
0
 private static System.Xml.XmlNode MakePropertyNode(System.Reflection.PropertyInfo memberInfo,
                                                    System.Xml.XmlDocument ownerdoc)
 {
     System.Xml.XmlNode nodeMember;
     nodeMember = Utility.xmlHelpers.NewElement(ownerdoc, "Property", memberInfo.Name);
     nodeMember.Attributes.Append(Utility.xmlHelpers.NewAttribute(ownerdoc, "Type", memberInfo.PropertyType.ToString()));
     nodeMember.Attributes.Append(Utility.xmlHelpers.NewBoolAttribute(ownerdoc, "CanRead", memberInfo.CanRead));
     nodeMember.Attributes.Append(Utility.xmlHelpers.NewBoolAttribute(ownerdoc, "CanWrite", memberInfo.CanWrite));
     MakeParameterNodes(nodeMember, memberInfo.GetIndexParameters());
     if (memberInfo.GetGetMethod() != null)
     {
         nodeMember.AppendChild(MakeMethodNode(memberInfo.GetGetMethod(), ownerdoc, false));
     }
     if (memberInfo.GetSetMethod() != null)
     {
         nodeMember.AppendChild(MakeMethodNode(memberInfo.GetSetMethod(), ownerdoc, false));
     }
     return(nodeMember);
 }
示例#11
0
 public override bool Process(PropertyInfo property, IMethodRemover methodRemover, IFacetHolder holder) {
     if ((property.PropertyType.IsPrimitive || TypeUtils.IsEnum(property.PropertyType)) && property.GetCustomAttribute<OptionallyAttribute>() != null) {
         Log.Warn("Ignoring Optionally annotation on primitive or un-readable parameter on " + property.ReflectedType + "." + property.Name);
         return false;
     }
     if (property.GetGetMethod() != null && !property.PropertyType.IsPrimitive) {
         return Process(property, holder);
     }
     return false;
 }
示例#12
0
 /// <summary>
 /// Recupera o valor de um membro de uma classe (Normalmente Propriedade) atraves da função membro.GetValue()
 /// </summary>
 /// <param name="objeto">Instancia do Objeto</param>
 /// <param name="membro">Instancia do membro do objeto</param>
 /// <returns></returns>
 private object getMemberValue(object objeto, System.Reflection.PropertyInfo membro)
 {
     if (membro.GetGetMethod().IsStatic)
     {
         return(membro.GetValue(null, null));
     }
     else
     {
         return(membro.GetValue(objeto, null));
     }
 }
        /// <summary>
        /// Initializes a new OSpace instance of the property class
        /// </summary>
        /// <param name="name">name of the property</param>
        /// <param name="typeUsage">TypeUsage object containing the property type and its facets</param>
        /// <param name="propertyInfo">for the property</param>
        internal NavigationProperty(string name, TypeUsage typeUsage, System.Reflection.PropertyInfo propertyInfo)
            : this(name, typeUsage)
        {
            System.Diagnostics.Debug.Assert(name == propertyInfo.Name, "different PropertyName?");
            if (null != propertyInfo)
            {
                System.Reflection.MethodInfo method;

                method = propertyInfo.GetGetMethod();
                PropertyGetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle));
            }
        }
示例#14
0
 //System.Reflection.PropertyInfo prop;
 /// <summary>
 /// ManagedProperty インスタンスを PropertyInfo から作成します。
 /// </summary>
 /// <param name="prop">PropertyInfo</param>
 public ManagedProperty(System.Reflection.PropertyInfo prop)
 {
     //this.prop=prop;
     System.Type type = prop.ReflectedType;
     if (prop.CanRead)
     {
         this[":propget:"] = new ManagedMethod(type, prop.GetGetMethod());
     }
     if (prop.CanWrite)
     {
         this[":propput:"] = new ManagedMethod(type, prop.GetSetMethod());
     }
 }
示例#15
0
 private static string GetGacDir()
 {
     System.Reflection.PropertyInfo gac = typeof(System.Environment).GetProperty("GacPath",
                                                                                 System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
     if (gac == null)
     {
         WriteLine("ERROR: Mono runtime not detected, please use " +
                   "the mono runtime for gacutil.exe");
         Environment.Exit(1);
     }
     System.Reflection.MethodInfo get_gac = gac.GetGetMethod(true);
     return((string)get_gac.Invoke(null, null));
 }
示例#16
0
        /// <summary>
        /// Initializes a new OSpace instance of the property class
        /// </summary>
        /// <param name="name">name of the property</param>
        /// <param name="typeUsage">TypeUsage object containing the property type and its facets</param>
        /// <param name="propertyInfo">for the property</param>
        /// <param name="entityDeclaringType">The declaring type of the entity containing the property</param>
        internal EdmProperty(string name, TypeUsage typeUsage, System.Reflection.PropertyInfo propertyInfo, RuntimeTypeHandle entityDeclaringType)
            : this(name, typeUsage)
        {
            System.Diagnostics.Debug.Assert(name == propertyInfo.Name, "different PropertyName");
            if (null != propertyInfo)
            {
                System.Reflection.MethodInfo method;

                method = propertyInfo.GetGetMethod(true); // return public or non-public getter
                PropertyGetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle));

                method = propertyInfo.GetSetMethod(true); // return public or non-public getter
                PropertySetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle));

                EntityDeclaringType = entityDeclaringType;
            }
        }
示例#17
0
 /// <summary>
 /// Metodo abstrato que salva o valor proprieamente dito no objeto da classe atraves da função membro.GetValue()
 /// </summary>
 /// <param name="objeto">Instancia do Objeto</param>
 /// <param name="membro">Instancia do membro do objeto</param>
 /// <param name="valor">Valor</param>
 private void setMemberValue(object objeto, System.Reflection.PropertyInfo membro, object valor)
 {
     try
     {
         if (membro.GetGetMethod().IsStatic)
         {
             membro.SetValue(null, valor, null);
         }
         else
         {
             membro.SetValue(objeto, valor, null);
         }
     }
     catch (System.Exception ex)
     {
         throw new System.Exception("setMemberValue() - Erro :" + ex.Message);
     }
 }
示例#18
0
        public static object GetPropertyValue(this object instance, string PropertyName)
        {
            if (PropertyName == null)
            {
                return(null);
            }
            Type type = instance.GetType();

            System.Reflection.PropertyInfo property = type.GetProperty(PropertyName);
            if (property == null)
            {
                return(null);
            }
            System.Reflection.MethodInfo method = property.GetGetMethod();
            if (method == null)
            {
                return(null);
            }
            return(method.Invoke(instance, null));
        }
示例#19
0
        public static bool IsDesignMode(Control control)
        {
            while (control != null)
            {
                System.Reflection.PropertyInfo siteProperty = control.GetType().GetProperty("Site");

                if (siteProperty != null)
                {
                    System.ComponentModel.ISite site = siteProperty.GetGetMethod().Invoke(control, new object[0]) as System.ComponentModel.ISite;
                    if (site != null && site.DesignMode)
                    {
                        return(true);
                    }
                }

                control = control.Parent;
            }

            return(false);
        }
示例#20
0
        // Ctor for imported properties
        public PropertyExpEntry(
            ISemanticResolver s,
            System.Reflection.PropertyInfo info
            )
        {
            m_info = info;

            m_strName = m_info.Name;

            // Class that we're defined in?
            System.Type tClrClass = info.DeclaringType;
            m_tClassDefined = s.ResolveCLRTypeToBlueType(tClrClass);

            // Symbol type
            this.m_type = s.ResolveCLRTypeToBlueType(info.PropertyType);

            // Spoof accessors
            if (info.CanRead) // Has Get
            {
                System.Reflection.MethodInfo mGet = info.GetGetMethod();
                m_symbolGet = new MethodExpEntry(s, mGet);
            }

            if (info.CanWrite) // Has Set
            {
                System.Reflection.MethodInfo mSet = info.GetSetMethod();
                m_symbolSet = new MethodExpEntry(s, mSet);
            }

            // Get modifiers
            System.Reflection.MethodInfo [] m = info.GetAccessors();

            m_mods = new Modifiers(m[0]);

            /*
             * m_mods = new Modifiers();
             * if (m[0].IsStatic) m_mods.SetStatic();
             * if (m[0].IsAbstract) m_mods.SetAbstract();
             * if (m[0].IsVirtual) m_mods.SetVirtual();
             */
        }
示例#21
0
        // based partially on : http://stackoverflow.com/questions/1253725/convert-ienumerable-to-datatable

        internal static System.Func <T, object> GetGetter <T>(System.Reflection.PropertyInfo property)
        {
            // get the get method for the property
            var method = property.GetGetMethod(true);

            // get the generic get-method generator (ReflectionUtility.GetSetterHelper<TTarget, TValue>)
            var genericHelper = typeof(ReflectionUtility).GetMethod(
                "GetGetterHelper",
                System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);

            // reflection call to the generic get-method generator to generate the type arguments
            var constructedHelper = genericHelper.MakeGenericMethod(
                method.DeclaringType,
                method.ReturnType);

            // now call it. The null argument is because it's a static method.
            object ret = constructedHelper.Invoke(null, new object[] { method });

            // cast the result to the action delegate and return it
            return((System.Func <T, object>)ret);
        }
        public static string Aggregate <TItem>(IList <TItem> array, string ValueMethod, char?split)
#endif
#endif
        {
            System.Reflection.PropertyInfo propertyValue = null;
            System.Reflection.MethodInfo   methodValue   = null;

            Type type = typeof(TItem);

            if (ValueMethod != null)
            {
                propertyValue = type.GetProperty(ValueMethod);
            }
            if (propertyValue != null)
            {
                methodValue = propertyValue.GetGetMethod();
            }

            string Result = string.Empty;

            foreach (TItem item in array)
            {
                if (split.HasValue && Result.Length > 0)
                {
                    Result += split.Value;
                }

                if (methodValue != null)
                {
                    GetValue <string> getValue = (GetValue <string>)Delegate.CreateDelegate(typeof(GetValue <string>), item, methodValue);
                    Result += getValue();
                }
                else
                {
                    Result += item.ToString();
                }
            }
            return(Result);
        }
示例#23
0
        internal CILPropertyImpl(
            CILReflectionContextImpl ctx,
            Int32 anID,
            System.Reflection.PropertyInfo pInfo)
            : base(ctx, anID, CILElementKind.Property, () => new CustomAttributeDataEventArgs(ctx, pInfo))
        {
            ArgumentValidator.ValidateNotNull("Property", pInfo);

            if (pInfo.DeclaringType
#if WINDOWS_PHONE_APP
                .GetTypeInfo()
#endif
                .IsGenericType&& !pInfo.DeclaringType
#if WINDOWS_PHONE_APP
                .GetTypeInfo()
#endif
                .IsGenericTypeDefinition)
            {
                throw new ArgumentException("This constructor may be used only on properties declared in genericless types or generic type definitions.");
            }

            InitFields(
                ref this.name,
                ref this.propertyAttributes,
                ref this.setMethod,
                ref this.getMethod,
                ref this.declaringType,
                ref this.constValue,
                ref this.customModifiers,
                new SettableValueForClasses <String>(pInfo.Name),
                new SettableValueForEnums <PropertyAttributes>((PropertyAttributes)pInfo.Attributes),
                () => ctx.Cache.GetOrAdd(pInfo.GetSetMethod(true)),
                () => ctx.Cache.GetOrAdd(pInfo.GetGetMethod(true)),
                () => (CILType)ctx.Cache.GetOrAdd(pInfo.DeclaringType),
                new SettableLazy <Object>(() => ctx.LaunchConstantValueLoadEvent(new ConstantValueLoadArgs(pInfo))),
                ctx.LaunchEventAndCreateCustomModifiers(new CustomModifierEventLoadArgs(pInfo)),
                true
                );
        }
示例#24
0
        static public System.Drawing.Bitmap GetIcon(string eventtypestr, string seltext = null)     // get ICON associated with the event type.
        {
            Type jtype = TypeOfJournalEntry(eventtypestr);

            if (jtype == null)
            {
                return(EDDiscovery.Properties.Resources.genericevent);
            }

            System.Reflection.MethodInfo m = jtype.GetMethod("IconSelect");                 // first we see if the class defines this function..

            if (m != null)
            {
                return((System.Drawing.Bitmap)m.Invoke(null, new Object [] { seltext }));    // if so, pass it the string and let it pick the icon
            }
            else
            {
                System.Reflection.PropertyInfo p      = jtype.GetProperty("Icon");          // else use the Icon property, or if its not defined, its a generic event
                System.Reflection.MethodInfo   getter = p?.GetGetMethod();
                return((getter != null) ? ((System.Drawing.Bitmap)getter.Invoke(null, null)) : EDDiscovery.Properties.Resources.genericevent);
            }
        }
        public static List <T> Where <T>(List <T> Array, string IfMethod)
#endif
        {
            Type type = typeof(T);

            System.Reflection.PropertyInfo propertyIf = type.GetProperty(IfMethod);

            System.Reflection.MethodInfo methodIf = propertyIf.GetGetMethod();
            string stmp = string.Empty;

            List <T> ret = new List <T>();

            foreach (T item in Array)
            {
                GetValue <bool> getBoolean = (GetValue <bool>)Delegate.CreateDelegate(typeof(GetValue <bool>), item, methodIf);

                if (getBoolean())
                {
                    ret.Add(item);
                }
            }
            return(ret);
        }
示例#26
0
        public bool GetValuesIndicated(Object o)                                            // For all in the Values list, fill in data given from fields in O
        {
            Type jtype = o.GetType();

            foreach (string k in values.Keys.ToList())
            {
                System.Reflection.PropertyInfo pi = jtype.GetProperty(k);
                if (pi != null)
                {
                    System.Reflection.MethodInfo getter = pi.GetGetMethod();
                    AddDataOfType(getter.Invoke(o, null), pi.PropertyType, k, 0);
                }
                else
                {
                    System.Reflection.FieldInfo fi = jtype.GetField(k);
                    if (fi != null)
                    {
                        AddDataOfType(fi.GetValue(o), fi.FieldType, k, 0);
                    }
                }
            }

            return(true);
        }
示例#27
0
 public override bool Process(PropertyInfo property, IMethodRemover methodRemover, IFacetHolder holder) {
     if (property.GetGetMethod() != null && TypeUtils.IsString(property.PropertyType)) {
         return Process(property, holder);
     }
     return false;
 }
示例#28
0
        public RMCommandParser(string commandLine,
                               object classForAutoAttributes)
        {
            m_commandLine = commandLine;

            Type type = classForAutoAttributes.GetType();

            System.Reflection.MemberInfo[] members = type.GetMembers();

            for (int i = 0; i < members.Length; i++)
            {
                object[] attributes = members[i].GetCustomAttributes(false);
                if (attributes.Length > 0)
                {
                    SwitchRecord rec = null;

                    foreach (Attribute attribute in attributes)
                    {
                        if (attribute is CommandLineSwitchAttribute)
                        {
                            CommandLineSwitchAttribute switchAttrib =
                                (CommandLineSwitchAttribute)attribute;

                            // Get the property information.  We're only handling
                            // properties at the moment!
                            if (members[i] is System.Reflection.PropertyInfo)
                            {
                                System.Reflection.PropertyInfo pi = (System.Reflection.PropertyInfo)members[i];

                                rec = new SwitchRecord(switchAttrib.Name,
                                                       switchAttrib.Description,
                                                       pi.PropertyType);

                                // Map in the Get/Set methods.
                                rec.SetMethod     = pi.GetSetMethod();
                                rec.GetMethod     = pi.GetGetMethod();
                                rec.PropertyOwner = classForAutoAttributes;

                                // Can only handle a single switch for each property
                                // (otherwise the parsing of aliases gets silly...)
                                break;
                            }
                        }
                    }

                    // See if any aliases are required.  We can only do this after
                    // a switch has been registered and the framework doesn't make
                    // any guarantees about the order of attributes, so we have to
                    // walk the collection a second time.
                    if (rec != null)
                    {
                        foreach (Attribute attribute in attributes)
                        {
                            if (attribute is CommandLineAliasAttribute)
                            {
                                CommandLineAliasAttribute aliasAttrib =
                                    (CommandLineAliasAttribute)attribute;
                                rec.AddAlias(aliasAttrib.Alias);
                            }
                        }
                    }

                    // Assuming we have a switch record (that may or may not have
                    // aliases), add it to the collection of switches.
                    if (rec != null)
                    {
                        if (m_switches == null)
                        {
                            m_switches = new System.Collections.ArrayList();
                        }
                        m_switches.Add(rec);
                    }
                }
            }
        }
 public T _Mod_GetGenericPropertyValue <T>(string name, Object[] index)
 {
     System.Reflection.PropertyInfo prop = this.GetType().GetProperty(name);
     return((T)prop.GetValue(prop.GetGetMethod().IsStatic ? null : this, index));
 }
示例#30
0
 //THIS DOESNT WORK - REMOVED FROM THE CHECK FUNCTION FOR NOW
 bool ProcessStructVariableTypes(object input, int inputType)
 {
     if (inputType == 0)
     {
         System.Reflection.PropertyInfo p = input as System.Reflection.PropertyInfo;
         Debug.Log("name: " + p.Name + " attributes: " + p.Attributes + " declaring type: " + p.DeclaringType + " accessors: " + p.GetAccessors() + " attributes: " + p.GetCustomAttributes(true) + " getmethod: " + p.GetGetMethod() + " setmethod: " + p.GetSetMethod() + " type: " + p.GetType() + " membertype: " + p.MemberType + " module: " + p.Module + " proptype: " + p.PropertyType + " reftype: " + p.ReflectedType);
         CompleteVariableSetup(16);
         return(false);
     }
     return(false);
 }
示例#31
0
 public override bool Process(PropertyInfo property, IMethodRemover methodRemover, IFacetHolder holder) {
     if (property.GetGetMethod() != null) {
         return Process(property, holder);
     }
     return false;
 }
示例#32
0
 public object InvokeGet(object target)
 {
     return(_property.GetGetMethod().Invoke(target, null));
 }
        private static System.Func <object, object> FindMember(Type type, string name)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            lock (_memberAccessors)
            {
                Dictionary <string, System.Func <object, object> > members;
                System.Func <object, object> accessor = null;

                if (_memberAccessors.TryGetValue(type, out members))
                {
                    if (members.TryGetValue(name, out accessor))
                    {
                        return(accessor);
                    }
                }
                else
                {
                    members = new Dictionary <string, System.Func <object, object> >();
                    _memberAccessors[type] = members;
                }

                // must look up using reflection
                string methodSuffix      = char.ToUpperInvariant(name[0]) + name.Substring(1);
                bool   checkOriginalName = !string.Equals(methodSuffix, name);

                MethodInfo method = null;
                if (method == null)
                {
                    PropertyInfo p = type.GetProperty(methodSuffix);
                    if (p == null && checkOriginalName)
                    {
                        p = type.GetProperty(name);
                    }

                    if (p != null)
                    {
                        method = p.GetGetMethod();
                    }
                }

                if (method == null)
                {
                    method = type.GetMethod("Get" + methodSuffix, Type.EmptyTypes);
                    if (method == null && checkOriginalName)
                    {
                        method = type.GetMethod("Get" + name, Type.EmptyTypes);
                    }
                }

                if (method == null)
                {
                    method = type.GetMethod("get_" + methodSuffix, Type.EmptyTypes);
                    if (method == null && checkOriginalName)
                    {
                        method = type.GetMethod("get_" + name, Type.EmptyTypes);
                    }
                }

                if (method == null)
                {
                    method = type.GetMethod(name, Type.EmptyTypes);
                }

                if (method != null)
                {
                    accessor = BuildAccessor(method);
                }
                else
                {
                    // try for an indexer
                    method = type.GetMethod("get_Item", new Type[] { typeof(string) });
                    if (method == null)
                    {
                        var property = type.GetProperties().FirstOrDefault(IsIndexer);
                        if (property != null)
                        {
                            method = property.GetGetMethod();
                        }
                    }

                    if (method != null)
                    {
                        accessor = BuildAccessor(method, name);
                    }
                    else
                    {
                        // try for a visible field
                        FieldInfo field = type.GetField(name);
                        // also check .NET naming convention for fields
                        if (field == null)
                        {
                            field = type.GetField("_" + name);
                        }

                        if (field != null)
                        {
                            accessor = BuildAccessor(field);
                        }
                    }
                }

                members[name] = accessor;

                return(accessor);
            }
        }