public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
        {
            HelpEntity helpResult  = null;
            var        description = "";

            if ((propertyMemberAst.Parent as TypeDefinitionAst).IsClass)
            {
                var attributes = propertyMemberAst.Attributes.Count >= 0 ?
                                 $", with attributes '{string.Join(", ", propertyMemberAst.Attributes.Select(p => p.TypeName.Name))}'." :
                                 ".";
                description = $"Property '{propertyMemberAst.Name}' of type '{propertyMemberAst.PropertyType.TypeName.FullName}'{attributes}";
                helpResult  = HelpTableQuery("about_classes");
                helpResult.DocumentationLink += "#class-properties";
            }

            if ((propertyMemberAst.Parent as TypeDefinitionAst).IsEnum)
            {
                description = $"Enum label '{propertyMemberAst.Name}', with value '{propertyMemberAst.InitialValue}'.";
                helpResult  = HelpTableQuery("about_enum");
            }

            explanations.Add(new Explanation()
            {
                Description     = description,
                CommandName     = "Property member",
                HelpResult      = helpResult,
                TextToHighlight = propertyMemberAst.Name
            }.AddDefaults(propertyMemberAst, explanations));

            return(base.VisitPropertyMember(propertyMemberAst));
        }
Esempio n. 2
0
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     if (!ValidateExtend(symbolRef.ScriptRegion.Text, propertyMemberAst.Name, propertyMemberAst))
     {
         return(AstVisitAction.Continue);
     }
     return(AstVisitAction.StopVisit);
 }
Esempio n. 3
0
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)  //confirmed
 {
     if (propertyMemberAst.ToString().Contains(symbolRef.ScriptRegion.Text))
     {
         ValidateExtend(symbolRef.ScriptRegion.Text, propertyMemberAst.Name, propertyMemberAst);
     }
     return(base.VisitPropertyMember(propertyMemberAst));
 }
 public virtual MemberAst VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return(new PropertyMemberAst(
                propertyMemberAst.Extent,
                propertyMemberAst.Name,
                propertyMemberAst.PropertyType?.Rewrite(this, SyntaxKind.TypeConstraint),
                propertyMemberAst.Attributes?.RewriteAll(this, SyntaxKind.Attribute),
                propertyMemberAst.PropertyAttributes,
                propertyMemberAst.InitialValue?.Rewrite(this, SyntaxKind.Expression)));
 }
Esempio n. 5
0
        private PSClassInfo ConvertToClassInfo(PSModuleInfo module, ScriptBlockAst ast, TypeDefinitionAst statement)
        {
            PSClassInfo classInfo = new PSClassInfo(statement.Name);

            Dbg.Assert(statement.Name != null, "statement should have a name.");
            classInfo.Module = module;
            Collection <PSClassMemberInfo> properties = new Collection <PSClassMemberInfo>();

            foreach (var member in statement.Members)
            {
                PropertyMemberAst propAst = member as PropertyMemberAst;
                if (propAst != null)
                {
                    Dbg.Assert(propAst.Name != null, "PropName cannot be null");
                    Dbg.Assert(propAst.PropertyType != null, "PropertyType cannot be null");
                    Dbg.Assert(propAst.PropertyType.TypeName != null, "Property TypeName cannot be null");
                    Dbg.Assert(propAst.Extent != null, "Property Extent cannot be null");
                    Dbg.Assert(propAst.Extent.Text != null, "Property ExtentText cannot be null");

                    PSClassMemberInfo classProperty = new PSClassMemberInfo(propAst.Name,
                                                                            propAst.PropertyType.TypeName.FullName,
                                                                            propAst.Extent.Text);
                    properties.Add(classProperty);
                }
            }

            classInfo.UpdateMembers(properties);

            string mamlHelpFile = null;

            if (ast.GetHelpContent() != null)
            {
                mamlHelpFile = ast.GetHelpContent().MamlHelpFile;
            }

            if (!String.IsNullOrEmpty(mamlHelpFile))
            {
                classInfo.HelpFile = mamlHelpFile;
            }

            return(classInfo);
        }
Esempio n. 6
0
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return AstVisitAction.Continue;
 }
Esempio n. 7
0
 public object VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     throw PSTraceSource.NewArgumentException(nameof(propertyMemberAst));
 }
Esempio n. 8
0
 /// <summary/>
 public virtual AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst) => DefaultVisit(propertyMemberAst);
Esempio n. 9
0
 public object VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     throw new System.NotImplementedException();
 }
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return(Visit(propertyMemberAst));
 }
Esempio n. 11
0
 public override MemberAst VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 => VisitOther(base.VisitPropertyMember(propertyMemberAst));
Esempio n. 12
0
 public object VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return(false);
 }
Esempio n. 13
0
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst) => VisitAst(propertyMemberAst);
Esempio n. 14
0
 /// <summary/>
 public virtual object VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return(null);
 }
Esempio n. 15
0
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return(AstVisitAction.Continue);
 }
Esempio n. 16
0
        /// <summary>
        /// True if it is a key property.
        /// </summary>
        /// <param name="parser"></param>
        /// <param name="propertyMemberAst">The property member AST</param>
        /// <param name="hasKey">True if it is a key property; otherwise, false.</param>
        private static void CheckKey(Parser parser, PropertyMemberAst propertyMemberAst, ref bool hasKey)
        {
            foreach (var attr in propertyMemberAst.Attributes)
            {
                if (attr.TypeName.GetReflectionAttributeType() == typeof(DscPropertyAttribute))
                {
                    foreach (var na in attr.NamedArguments)
                    {
                        if (na.ArgumentName.Equals("Key", StringComparison.OrdinalIgnoreCase))
                        {
                            object attrArgValue;
                            if (IsConstantValueVisitor.IsConstant(na.Argument, out attrArgValue, forAttribute: true, forRequires: false)
                                && LanguagePrimitives.IsTrue(attrArgValue))
                            {
                                hasKey = true;

                                bool keyPropertyTypeAllowed = false;
                                var propertyType = propertyMemberAst.PropertyType;
                                if (propertyType != null)
                                {
                                    TypeName typeName = propertyType.TypeName as TypeName;
                                    if (typeName != null)
                                    {
                                        var type = typeName.GetReflectionType();
                                        if (type != null)
                                        {
                                            keyPropertyTypeAllowed = type == typeof(string) || type.IsInteger();
                                        }
                                        else
                                        {
                                            var typeDefinitionAst = typeName._typeDefinitionAst;
                                            if (typeDefinitionAst != null)
                                            {
                                                keyPropertyTypeAllowed = typeDefinitionAst.IsEnum;
                                            }
                                        }
                                    }
                                }
                                if (!keyPropertyTypeAllowed)
                                {
                                    parser.ReportError(propertyMemberAst.Extent, () => ParserStrings.DscResourceInvalidKeyProperty);
                                }
                                return;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 17
0
        public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
        {
            if (propertyMemberAst.PropertyType != null)
            {
                // Type must be resolved, but if it's not, the error was reported by the symbol resolver.
                var type = propertyMemberAst.PropertyType.TypeName.GetReflectionType();

                if (type != null && (type == typeof(void) || type.GetTypeInfo().IsGenericTypeDefinition))
                {
                    _parser.ReportError(propertyMemberAst.PropertyType.Extent, () => ParserStrings.TypeNotAllowedForProperty,
                        propertyMemberAst.PropertyType.TypeName.FullName);
                }
            }
            _memberScopeStack.Push(propertyMemberAst);
            return AstVisitAction.Continue;
        }
Esempio n. 18
0
            private PropertyBuilder EmitPropertyIl(PropertyMemberAst propertyMemberAst, Type type)
            {
                // backing field is always private.
                var backingFieldAttributes = FieldAttributes.Private;
                // The property set and property get methods require a special set of attributes.
                var getSetAttributes = Reflection.MethodAttributes.SpecialName | Reflection.MethodAttributes.HideBySig;
                getSetAttributes |= propertyMemberAst.IsPublic ? Reflection.MethodAttributes.Public : Reflection.MethodAttributes.Private;
                if (propertyMemberAst.IsStatic)
                {
                    backingFieldAttributes |= FieldAttributes.Static;
                    getSetAttributes |= Reflection.MethodAttributes.Static;
                }
                // C# naming convention for backing fields.
                string backingFieldName = String.Format(CultureInfo.InvariantCulture, "<{0}>k__BackingField", propertyMemberAst.Name);
                var backingField = _typeBuilder.DefineField(backingFieldName, type, backingFieldAttributes);

                bool hasValidateAttributes = false;
                if (propertyMemberAst.Attributes != null)
                {
                    for (int i = 0; i < propertyMemberAst.Attributes.Count; i++)
                    {
                        Type attributeType = propertyMemberAst.Attributes[i].TypeName.GetReflectionAttributeType();
                        if (attributeType != null && attributeType.IsSubclassOf(typeof(ValidateArgumentsAttribute)))
                        {
                            hasValidateAttributes = true;
                            break;
                        }
                    }
                }

                // The last argument of DefineProperty is null, because the property has no parameters. 
                PropertyBuilder property = _typeBuilder.DefineProperty(propertyMemberAst.Name, Reflection.PropertyAttributes.None, type, null);

                // Define the "get" accessor method.
                MethodBuilder getMethod = _typeBuilder.DefineMethod(String.Concat("get_", propertyMemberAst.Name), getSetAttributes, type, Type.EmptyTypes);
                ILGenerator getIlGen = getMethod.GetILGenerator();
                if (propertyMemberAst.IsStatic)
                {
                    // static
                    getIlGen.Emit(OpCodes.Ldsfld, backingField);
                    getIlGen.Emit(OpCodes.Ret);
                }
                else
                {
                    // instance
                    getIlGen.Emit(OpCodes.Ldarg_0);
                    getIlGen.Emit(OpCodes.Ldfld, backingField);
                    getIlGen.Emit(OpCodes.Ret);
                }

                // Define the "set" accessor method.
                MethodBuilder setMethod = _typeBuilder.DefineMethod(String.Concat("set_", propertyMemberAst.Name), getSetAttributes, null, new Type[] { type });
                ILGenerator setIlGen = setMethod.GetILGenerator();

                if (hasValidateAttributes)
                {
                    var typeToLoad = _typeBuilder.AsType();
                    setIlGen.Emit(OpCodes.Ldtoken, typeToLoad);
                    setIlGen.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle")); // load current Type on stack
                    setIlGen.Emit(OpCodes.Ldstr, propertyMemberAst.Name); // load name of Property
                    setIlGen.Emit(propertyMemberAst.IsStatic ? OpCodes.Ldarg_0 : OpCodes.Ldarg_1); // load set value
                    if (type.GetTypeInfo().IsValueType)
                    {
                        setIlGen.Emit(OpCodes.Box, type);
                    }
                    setIlGen.Emit(OpCodes.Call, CachedReflectionInfo.ClassOps_ValidateSetProperty);
                }

                if (propertyMemberAst.IsStatic)
                {
                    setIlGen.Emit(OpCodes.Ldarg_0);
                    setIlGen.Emit(OpCodes.Stsfld, backingField);
                }
                else
                {
                    setIlGen.Emit(OpCodes.Ldarg_0);
                    setIlGen.Emit(OpCodes.Ldarg_1);
                    setIlGen.Emit(OpCodes.Stfld, backingField);
                }
                setIlGen.Emit(OpCodes.Ret);

                // Map the two methods created above to our PropertyBuilder to  
                // their corresponding behaviors, "get" and "set" respectively. 
                property.SetGetMethod(getMethod);
                property.SetSetMethod(setMethod);

                if (propertyMemberAst.IsHidden)
                {
                    property.SetCustomAttribute(s_hiddenCustomAttributeBuilder);
                }

                return property;
            }
Esempio n. 19
0
            private void DefineProperty(PropertyMemberAst propertyMemberAst)
            {
                if (_definedProperties.ContainsKey(propertyMemberAst.Name))
                {
                    _parser.ReportError(propertyMemberAst.Extent, () => ParserStrings.MemberAlreadyDefined, propertyMemberAst.Name);
                    return;
                }

                _definedProperties.Add(propertyMemberAst.Name, propertyMemberAst);

                Type type;
                if (propertyMemberAst.PropertyType == null)
                {
                    type = typeof(object);
                }
                else
                {
                    type = propertyMemberAst.PropertyType.TypeName.GetReflectionType();
                    Diagnostics.Assert(type != null, "Semantic checks should have ensure type can't be null");
                }

                PropertyBuilder property = this.EmitPropertyIl(propertyMemberAst, type);
                // Define custom attributes on the property, not on the backingField
                DefineCustomAttributes(property, propertyMemberAst.Attributes, _parser, AttributeTargets.Field | AttributeTargets.Property);
            }
 object ICustomAstVisitor2.VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 => ProcessRewriter(VisitPropertyMember, propertyMemberAst);
Esempio n. 21
0
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst ast)
 {
     return(Check(ast));
 }
Esempio n. 22
0
 /// <summary/>
 public virtual AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst) { return AstVisitAction.Continue; }
Esempio n. 23
0
 /// <summary/>
 public virtual AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return(AstVisitAction.Continue);
 }
Esempio n. 24
0
 public object VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return null;
 }
Esempio n. 25
0
 public object VisitPropertyMember(PropertyMemberAst propertyMemberAst)
 {
     return(AutomationNull.Value);
 }
Esempio n. 26
0
 public override AstVisitAction VisitPropertyMember(PropertyMemberAst ast) { return Check(ast); }