private ParameterInfo GetSetAccessorParameter(PropertyInfo pi)
 {
     return pi
         .GetAccessors()
         .First()
         .GetParameters()
         .First();
 }
Exemplo n.º 2
0
        //Check for public methods
        public bool HasPublicProperties(PropertyInfo property)
        {
            if (property == null)
            {
                throw new NullReferenceException("Must supply the property parameter");
            }

            foreach (MethodInfo info in property.GetAccessors(true))
            {
                if (info.IsPublic == false)
                    return true;
            }
            return false;
        }
        static StackObject *GetAccessors_6(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Reflection.PropertyInfo instance_of_this_method = (System.Reflection.PropertyInfo) typeof(System.Reflection.PropertyInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetAccessors();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether the specified property is public.
        /// </summary>
        /// <param name="pi">The property.</param>
        /// <returns>
        /// <c>true</c> if the specified property is public; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsPublicProperty(PropertyInfo pi)
        {
            foreach(var m in pi.GetAccessors())
                if(m.IsPublic)
                    return true;

            return false;
        }
Exemplo n.º 5
0
        FieldModel GetPropertyModel(PropertyInfo propertyInfo) {
            if (propertyInfo.DeclaringType != Type) return null;
            TypeDesc typeDesc = ModelScope.TypeScope.GetTypeDesc(propertyInfo.PropertyType, propertyInfo);

            if (!propertyInfo.CanRead) return null;

            foreach (MethodInfo accessor in propertyInfo.GetAccessors())
                if ((accessor.Attributes & MethodAttributes.HasSecurity) != 0)
                    throw new InvalidOperationException(Res.GetString(Res.XmlPropertyHasSecurityAttributes, propertyInfo.Name, Type.FullName));
            if ((propertyInfo.DeclaringType.Attributes & TypeAttributes.HasSecurity) != 0)
                throw new InvalidOperationException(Res.GetString(Res.XmlPropertyHasSecurityAttributes, propertyInfo.Name, Type.FullName));
                
            MethodInfo getMethod = propertyInfo.GetGetMethod();
            ParameterInfo[] parameters = getMethod.GetParameters();
            if (parameters.Length > 0) return null;

            return new FieldModel(propertyInfo, propertyInfo.PropertyType, typeDesc);
        }
Exemplo n.º 6
0
		protected override string GetPropertyDescription (PropertyInfo property, object instance)
		{
			StringBuilder sb = new StringBuilder ();
			AddAttributes (sb, property);
			AddMethodQualifiers (sb, property.GetAccessors(true)[0]);

			string getter = null;
			if (property.CanRead) {
				string v = null;
				try {
					v = string.Format (" /* = {0} */", GetValue (property.GetValue (instance, null)));
				}
				catch {
				}
				getter = string.Format (PropertyGetFormat, v);
			}

			string setter = null;
			if (property.CanWrite)
				setter = PropertySet;

			sb.AppendFormat (PropertyFormat, property.PropertyType, property.Name, getter, setter);

			return sb.ToString();
		}
Exemplo n.º 7
0
		private string GetPropertyContractValue(PropertyInfo property)
		{
			return GetMethodContractValue(property.GetAccessors(true)[0]);
		}
Exemplo n.º 8
0
        static private void AppendPropertyInfo(PropertyInfo property, StringBuilder sb)
        {
            sb.Append(".property ");

            foreach (var attribute in property.GetCustomAttributesData())
            {
                AppendCustomAttributeData(attribute, sb);
                sb.Append(" ");
            }
            foreach (var modreq in property.GetRequiredCustomModifiers())
            {
                sb.Append("modreq(");
                AppendType(modreq, sb);
                sb.Append(") ");
            }
            foreach (var modopt in property.GetOptionalCustomModifiers())
            {
                sb.Append("modopt(");
                AppendType(modopt, sb);
                sb.Append(") ");
            }

            if (property.CanRead && property.CanWrite)
            {
                sb.Append("readwrite ");
            }
            else if (property.CanRead)
            {
                sb.Append("readonly ");
            }
            else if (property.CanWrite)
            {
                sb.Append("writeonly ");
            }

            if (property.Attributes.HasFlag(PropertyAttributes.SpecialName)) sb.Append("specialname ");
            if (property.Attributes.HasFlag(PropertyAttributes.RTSpecialName)) sb.Append("rtspecialname ");

            var propertyAccesors = property.GetAccessors();
            if (propertyAccesors.Length > 0)
            {
                sb.Append(propertyAccesors[0].IsStatic ? "static " : "instance ");
            }
            AppendType(property.PropertyType, sb);
            sb.Append(" ");
            sb.Append(property.Name);

            var indexParameters = property.GetIndexParameters();
            if (indexParameters.Length > 0)
            {
                sb.Append("(");
                foreach (var indexParameter in indexParameters)
                {
                    AppendParameterInfo(indexParameter, sb);
                    AppendComma(sb);
                }
                RemoveTrailingComma(sb);
                sb.Append(")");
            }
        }
 private void VerifyAddMethodsResult(PropertyInfo myProperty, MethodBuilder expectedMethod)
 {
     MethodInfo[] actualMethods = myProperty.GetAccessors(true);
     Assert.Equal(1, actualMethods.Length);
     Assert.Equal(expectedMethod.Name, actualMethods[0].Name);
 }
Exemplo n.º 10
0
        public PropertyDetail(RootDetail parent, PropertyInfo pi)
            : base(parent, pi)
        {
            _name = pi.Name;
            _category = "property";

            MethodInfo[] methods = pi.GetAccessors(true);
            foreach (MethodInfo mi in methods)
            {
                MethodDetail m = new MethodDetail(this, mi);

                if ((m.Name.Length > 3) && (mi.IsSpecialName))
                {
                    m.Name = m.Name.Substring(0, 3);
                }

                m.Declaration = null;
                _children.Add(m);
            }

            if (pi.GetIndexParameters().Length > 0)
            {
                CodeStringBuilder csbParameters = new CodeStringBuilder(AppendMode.Text);

                foreach (ParameterInfo ip in pi.GetIndexParameters())
                {
                    csbParameters.AppendParameterType(ip);
                    csbParameters.AppendText(", ");

                    _parameterCount++;
                }

                csbParameters.RemoveCharsFromEnd(2);

                _parameterTypesList = csbParameters.ToString();
            }

            _visibility = VisibilityUtil.GetMostVisible(FilterChildren<MethodDetail>());

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

            csb.AppendType(pi.PropertyType);
            csb.AppendText(" ");
            csb.AppendText(pi.Name);

            if (this.ParameterCount > 0)
            {
                csb.AppendText("[");
                csb.AppendText(this.ParameterTypesList);
                csb.AppendText("]");
            }

            csb.Mode = AppendMode.Html;

            csb.AppendNewline();
            csb.AppendText("{");
            csb.AppendNewline();
            csb.AppendIndent();

            foreach (MethodDetail mi in FilterChildren<MethodDetail>())
            {
                if (mi.Visibility != _visibility)
                {
                    csb.AppendVisibility(mi.Visibility);
                    csb.AppendText(" ");
                }

                csb.AppendText(mi.Name);
                csb.AppendText("; ");
            }

            csb.AppendNewline();
            csb.AppendText("}");

            _declaration = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Determines lowest accessibility of all property accessors and other member attributes.
        /// </summary>
        public static PhpMemberAttributes GetPropertyAttributes(PropertyInfo/*!*/info)
        {
            var accessors = info.GetAccessors(true);
            PhpMemberAttributes attributes = PhpMemberAttributes.None;
            
            // find lowest visibility in all property accessors:
            for (int i = 0; i < accessors.Length; i++)
            {
                if (accessors[i].IsStatic)
                    attributes |= PhpMemberAttributes.Static;

                if (accessors[i].IsPrivate)
                    attributes |= PhpMemberAttributes.Private;
                else if (accessors[i].IsFamily)
                    attributes |= PhpMemberAttributes.Protected;
                //else if (accessors[i].IsPublic)
                //    visibility |= PhpMemberAttributes.Public;
            }

            return attributes;
        }
 public static bool IsPublic(this PropertyInfo pi)
 {
     return((pi.GetAccessors()[0].Attributes & MethodAttributes.Public) == MethodAttributes.Public);
 }
 public static bool IsStatic(this PropertyInfo pi)
 {
     return(pi.GetAccessors()[0].IsStatic);
 }
    public override void AppendPropertySignature(StringBuilder sb, PropertyInfo pi) 
    {
      MethodInfo getter = pi.GetGetMethod();
      if (getter != null) 
      {
        sb.Append( indentPrefix );

        AppendMethodVisibility( sb, getter );

        AppendMethodReturnType( sb, getter, defaultAbbreviation );

        if ((pi.Name.Equals("Item") || pi.Name.Equals("Items"))
          && getter.GetParameters().Length != 0) 
        {
          sb.Append("this");
          AppendIndexParameters( sb, getter, defaultAbbreviation );
        }
        else 
        {
          sb.Append( pi.Name );
        }

        sb.Append( " {" );

        MethodInfo[] mi = pi.GetAccessors();
        String accessors = "";
        for (int i = 0; i < mi.Length; i++) 
        {
          String modifiers = (IsVirtual(mi[i])) ? " virtual" : "";
          if (IsPropertySet(mi[i]))
            accessors = accessors + modifiers + " set;";
          else
            accessors = modifiers + " get;" + accessors;
        }
        sb.Append( accessors + " }" );
        sb.Append(lineSeparator);
      }
    }
Exemplo n.º 15
0
 private static void WriteProperty(string memberName, PropertyInfo propInfo)
 {
     Console.WriteLine("\t\tpublic {0} {1}", GetCSharpTypeName(propInfo.PropertyType), propInfo.Name);
     Console.WriteLine("\t\t{");
     var accessors = propInfo.GetAccessors();
     if (accessors.Count(x => x.Name.StartsWith("get_")) > 0)
     {
         Console.WriteLine("\t\t\tget {{ return {0}.{1}; }}", memberName, propInfo.Name);
     }
     if (accessors.Count(x => x.Name.StartsWith("set_")) > 0)
     {
         Console.WriteLine("\t\t\tset {{ {0}.{1} = value; }}", memberName, propInfo.Name);
     }
     Console.WriteLine("\t\t}");
 }
        /// <summary>
        /// Determines whether a given property has a setter accessor.
        /// </summary>
        /// <param name="property">The property to check.</param>
        /// <returns>True if the property has a setter accessor, otherwise false.</returns>
        private static bool HasSetter(PropertyInfo property)
        {
            MethodInfo[] methods;
            bool result;

            result = false;

            methods = property.GetAccessors(false);
            foreach (MethodInfo info in methods)
            {
                if (info.Name.StartsWith("set_"))
                {
                    result = true;
                    break;
                }
            }

            return result;
        }
Exemplo n.º 17
0
        private static CodeMemberProperty CreatePropertyOverride(string structType, PropertyInfo pi,
            CodeMethodReferenceExpression changeMethod)
        {
            CodeMemberProperty mp = new CodeMemberProperty();
            mp.Name = pi.Name;
            mp.Attributes = MemberAttributes.Override |
                (pi.GetAccessors(true)[0].IsPublic ? MemberAttributes.Public : MemberAttributes.Family);
            mp.Type = new CodeTypeReference(pi.PropertyType);
            mp.HasGet = mp.HasSet = true;

            mp.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression() {
                TargetObject = new CodePropertyReferenceExpression() {
                    TargetObject = new CodeFieldReferenceExpression() {
                        TargetObject = new CodeThisReferenceExpression(),
                        FieldName = ShieldedField,
                    },
                    PropertyName = ShieldedValueProperty,
                },
                FieldName = pi.Name,
            }));

            // call base setter first, so they can see the old value (using getter) and new (using value)
            mp.SetStatements.Add(new CodeAssignStatement(
                new CodePropertyReferenceExpression() {
                    TargetObject = new CodeBaseReferenceExpression(),
                    PropertyName = pi.Name,
                }, new CodePropertySetValueReferenceExpression()));
            // using Modify has a huge advantage - if a class is big, we don't want to be passing
            // copies of the underlying struct around.
            mp.SetStatements.Add(new CodeSnippetStatement(
                string.Format("{0}.Modify((ref {1} a) => a.@{2} = value);",
                    ShieldedField, structType, pi.Name)));

            if (changeMethod != null)
                mp.SetStatements.Add(new CodeMethodInvokeExpression(
                    changeMethod, new CodePrimitiveExpression(pi.Name)));

            return mp;
        }
Exemplo n.º 18
0
 internal static bool IsInteresting(PropertyInfo pi)
 {
     if (!pi.CanRead || !pi.CanWrite)
         return false;
     var access = pi.GetAccessors(true);
     // must have both accessors, both virtual, and both either public or protected, no mixing.
     if (access == null || access.Length != 2 || !access[0].IsVirtual)
         return false;
     if (access[0].IsPublic && access[1].IsFamily || access[0].IsFamily && access[1].IsPublic)
         throw new InvalidOperationException("Virtual property accessors must both be public, or both protected.");
     return access[0].IsPublic && access[1].IsPublic || access[0].IsFamily && access[1].IsFamily;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Shows property of an encodeable object in the control.
        /// </summary>
        private void ShowValue(ref int index, ref bool overwrite, IEncodeable value, PropertyInfo property)
        {            
            // get the name of the property.
            string name = Utils.GetDataMemberName(property);

            if (name == null)
            {
                return;
            }
            
            // get the property value.
            object propertyValue = null;

            MethodInfo[] accessors = property.GetAccessors();

            for (int ii = 0; ii < accessors.Length; ii++)
            {
                if (accessors[ii].ReturnType == property.PropertyType)
                {
                    propertyValue = accessors[ii].Invoke(value, null);
                    break;
                }
            }
           
            if (propertyValue is Variant)
            {
                propertyValue = ((Variant)propertyValue).Value;
            }
            
            // update the list view.
            UpdateList(
                ref index,
                ref overwrite,
                value,
                propertyValue,
                property,
                name,
                property.PropertyType.Name);
        }
Exemplo n.º 20
0
        public override void AppendPropertySignature(StringBuilder sb, PropertyInfo pi) {
            MethodInfo getter = pi.GetGetMethod();
            if (getter != null) {
                sb.Append( "<tr>" );
                sb.Append( "<td valign=top>" );
                sb.Append( "<table width=100% cellpadding=0 cellspacing=0><tr><td>" );

                AppendMethodVisibility( sb, getter );
                sb.Append( "&nbsp;</td><td align=right>" );
                AppendMethodReturnType( sb, getter, TypeNames.Short );
                sb.Append( "</td></tr></table>" );
                sb.Append( "</td>" );
                sb.Append( "<td>" );
                
                                if ((pi.Name.Equals("Item") || pi.Name.Equals("Items"))
                    && getter.GetParameters().Length != 0) {
                AppendMemberName( sb, "this" );
                    AppendIndexParameters( sb, getter, defaultAbbreviation );
                }
                else {
                AppendMemberName( sb, pi.Name );
                }

                
                sb.Append( " {" );

                MethodInfo[] mi = pi.GetAccessors();
                String accessors = "";
                for (int i = 0; i < mi.Length; i++) {
                    String modifiers = (IsVirtual(mi[i])) ? " virtual" : "";
                    if (IsPropertySet(mi[i]))
                        accessors = accessors + modifiers + " set;";
                    else
                        accessors = modifiers + " get;" + accessors;
                }
                sb.Append( accessors + " }\n" );
               sb.Append( "</td>" );
                sb.Append("</tr>\n");
            }
        }
Exemplo n.º 21
0
        private ProtoCore.AST.AssociativeAST.AssociativeNode ParseProperty(PropertyInfo p)
        {
            if (null == p || SupressesImport(p))
                return null;
            
            //Index properties are not parsed as property at this moment.
            ParameterInfo[] indexParams = p.GetIndexParameters();
            if (null != indexParams && indexParams.Length > 0)
                return null;

            MethodInfo m = p.GetAccessors(false)[0];
            //If this method hides the base class accessor method by signature
            if (m.IsHideBySig)
            {
                //Check if it has a base class
                Type baseType = p.DeclaringType.BaseType;
                PropertyInfo baseProp = (baseType != null) ? GetProperty(ref baseType, p.Name) : null;
                //If this property is also declared in base class, then no need to add this is derived class.
                if(null != baseProp && baseProp.DeclaringType != p.DeclaringType)
                {
                    //base class also has this method.
                    return null;
                }
            }
            
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = ParseArgumentDeclaration(p.Name, p.PropertyType);
            if(null != varDeclNode)
                varDeclNode.IsStatic = m.IsStatic;
            return varDeclNode;
        }
        private static bool UseableForSerialization(PropertyInfo property)
        {
            bool isUseable = property.CanRead && property.CanWrite;

            if (isUseable)
            {
                foreach (MethodInfo mi in property.GetAccessors(false))
                {
                    isUseable = isUseable && mi.IsPublic;
                }
            }

            isUseable = isUseable && TypeUseableForSerialization(property.PropertyType);

            return isUseable;
        }              
Exemplo n.º 23
0
		private bool IsHiding(PropertyInfo property, Type type)
		{
			if (!IsHiding((MemberInfo)property, type))
				return false;

			bool isIndexer = (property.Name == "Item");
			foreach (MethodInfo accessor in property.GetAccessors(true))
			{
				if (((accessor.Attributes & MethodAttributes.Virtual) != 0)
					&& ((accessor.Attributes & MethodAttributes.NewSlot) == 0))
					return false;

				// indexers only hide indexers with the same signature
				if (isIndexer && !IsHiding(accessor, type))
					return false;
			}

			return true;
		}
Exemplo n.º 24
0
        public static string CreatePropertyMarkup(string propertyName, Type propertyType, PropertyInfo propertyInfo)
        {
            if (propertyName == null)
                throw new ArgumentNullException("propertyName");
            if (propertyType == null)
                throw new ArgumentNullException("propertyType");
            if (propertyInfo == null)
                throw new ArgumentNullException("propertyInfo");

            string markup = CreateMemberMarkup(null, propertyType, propertyName, null);

            var propertyModifier = GetMemberModifiers(propertyInfo);

            markup += " {";

            foreach (var accessor in propertyInfo.GetAccessors())
            {
                var accessorModifier = GetMemberModifiers(accessor);

                if ((accessorModifier & (MemberModifier.Public | MemberModifier.Protected)) != 0)
                {
                    markup += " ";

                    if (
                        propertyModifier == MemberModifier.Public &&
                        accessorModifier.HasFlag(MemberModifier.Protected)
                    )
                        markup += "protected ";

                    markup += accessor.Name.Split('_')[0] + ";";
                }
            }

            markup += " }";

            return markup;
        }