Beispiel #1
0
        public PropertyBindingInfo(PropertyInfo propertyInfo)
        {
            this.propertyInfo = propertyInfo;
            if (propertyInfo.CanRead && propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsPublic)
            {
                if (propertyInfo.GetMethod.IsStatic)
                {
                    staticPair.getterName = "BindStaticRead_" + propertyInfo.Name;
                }
                else
                {
                    instancePair.getterName = "BindRead_" + propertyInfo.Name;
                }
            }

            if (propertyInfo.CanWrite && propertyInfo.SetMethod != null && propertyInfo.SetMethod.IsPublic)
            {
                if (propertyInfo.SetMethod.IsStatic)
                {
                    staticPair.setterName = "BindStaticWrite_" + propertyInfo.Name;
                }
                else
                {
                    instancePair.setterName = "BindWrite_" + propertyInfo.Name;
                }
            }

            this.regName = TypeBindingInfo.GetNamingAttribute(propertyInfo);
        }
        public EventBindingInfo(Type declaringType, EventInfo eventInfo)
        {
            this.declaringType = declaringType;
            this.eventInfo     = eventInfo;

            if (this.isStatic)
            {
                this.name = "BindStaticEvent_" + eventInfo.Name;
            }
            else
            {
                this.name = "BindEvent_" + eventInfo.Name;
            }

            this.regName = TypeBindingInfo.GetNamingAttribute(eventInfo);
        }
Beispiel #3
0
        public DelegateBindingInfo(Type declaringType, PropertyInfo propertyInfo)
        {
            this.declaringType = declaringType;
            this.delegateType  = propertyInfo.PropertyType;
            this.readable      = propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsPublic;
            this.writable      = propertyInfo.SetMethod != null && propertyInfo.SetMethod.IsPublic;
            this.isStatic      = (propertyInfo.GetMethod ?? propertyInfo.SetMethod).IsStatic;
            this.csName        = propertyInfo.Name;

            if (this.isStatic)
            {
                this.name = "BindStaticDelegate_" + propertyInfo.Name;
            }
            else
            {
                this.name = "BindDelegate_" + propertyInfo.Name;
            }

            this.regName = TypeBindingInfo.GetNamingAttribute(propertyInfo);
        }
Beispiel #4
0
        public bool isStatic; // 静态

        public DelegateBindingInfo(Type declaringType, FieldInfo fieldInfo)
        {
            this.declaringType = declaringType;
            this.delegateType  = fieldInfo.FieldType;
            this.readable      = true;
            this.writable      = !fieldInfo.IsInitOnly;
            this.isStatic      = fieldInfo.IsStatic;
            this.csName        = fieldInfo.Name;

            do
            {
                if (this.isStatic)
                {
                    this.name = "BindStaticDelegate_" + fieldInfo.Name;
                }
                else
                {
                    this.name = "BindDelegate_" + fieldInfo.Name;
                }
            } while (false);

            this.regName = TypeBindingInfo.GetNamingAttribute(fieldInfo);
        }
Beispiel #5
0
        public FieldBindingInfo(FieldInfo fieldInfo)
        {
            do
            {
                if (fieldInfo.IsLiteral)
                {
                    try
                    {
                        var cv     = fieldInfo.GetRawConstantValue();
                        var cvType = cv.GetType();
                        if (cvType == typeof(string))
                        {
                            constantValue = $"\"{cv}\"";
                            break;
                        }

                        if (cvType == typeof(int) ||
                            cvType == typeof(uint) ||
                            cvType == typeof(byte) ||
                            cvType == typeof(sbyte) ||
                            cvType == typeof(short) ||
                            cvType == typeof(ushort) ||
                            cvType == typeof(bool))
                        {
                            constantValue = $"{cv}";
                            break;
                        }

                        if (cvType == typeof(float))
                        {
                            var fcv = (float)cv;
                            if (!float.IsInfinity(fcv) &&
                                !float.IsNaN(fcv))
                            {
                                constantValue = $"{cv}";
                                break;
                            }
                        }

                        // if (cvType.IsPrimitive && cvType.IsValueType)
                        // {
                        //     constantValue = $"{cv}";
                        //     break;
                        // }
                    }
                    catch (Exception)
                    {
                    }
                }

                if (fieldInfo.IsStatic)
                {
                    this.getterName = "BindStaticRead_" + fieldInfo.Name;
                    if (!fieldInfo.IsInitOnly && !fieldInfo.IsLiteral)
                    {
                        this.setterName = "BindStaticWrite_" + fieldInfo.Name;
                    }
                }
                else
                {
                    this.getterName = "BindRead_" + fieldInfo.Name;
                    if (!fieldInfo.IsInitOnly && !fieldInfo.IsLiteral)
                    {
                        this.setterName = "BindWrite_" + fieldInfo.Name;
                    }
                }
            } while (false);

            this.regName   = TypeBindingInfo.GetNamingAttribute(fieldInfo);
            this.fieldInfo = fieldInfo;
        }