Esempio n. 1
0
        public override void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value)
        {
            if (adaptedProperty == null)
            {
                throw new ArgumentNullException("adaptedProperty");
            }
            if (!this.IsSettable(adaptedProperty))
            {
                throw new SetValueException("ReadOnlyCIMProperty", null, CimInstanceTypeAdapterResources.ReadOnlyCIMProperty, new object[] { adaptedProperty.Name });
            }
            CimProperty tag  = adaptedProperty.Tag as CimProperty;
            object      obj2 = value;

            if (obj2 != null)
            {
                Type    dotNetType;
                CimType cimType = tag.CimType;
                if (cimType == CimType.DateTime)
                {
                    dotNetType = typeof(object);
                }
                else if (cimType == CimType.DateTimeArray)
                {
                    dotNetType = typeof(object[]);
                }
                else
                {
                    dotNetType = CimConverter.GetDotNetType(tag.CimType);
                }
                obj2 = Adapter.PropertySetAndMethodArgumentConvertTo(value, dotNetType, CultureInfo.InvariantCulture);
            }
            tag.Value = obj2;
        }
Esempio n. 2
0
        public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty)
        {
            if (adaptedProperty == null)
            {
                throw new ArgumentNullException("adaptedProperty");
            }
            CimProperty tag = adaptedProperty.Tag as CimProperty;

            if (tag == null)
            {
                if (!adaptedProperty.Name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase))
                {
                    throw new ArgumentNullException("adaptedProperty");
                }
                return(ToStringCodeMethods.Type(typeof(string), false));
            }
            switch (tag.CimType)
            {
            case CimType.DateTime:
            case CimType.Reference:
            case CimType.Instance:
            case CimType.DateTimeArray:
            case CimType.ReferenceArray:
            case CimType.InstanceArray:
                return("CimInstance#" + tag.CimType.ToString());
            }
            return(ToStringCodeMethods.Type(CimConverter.GetDotNetType(tag.CimType), false));
        }
Esempio n. 3
0
        public static MethodAnalysis Analyze(this CimMethodDeclaration d, IDictionary <string, CimTypeDeclaration> typeRepo)
        {
            TypeSyntax returnType;
            var        dotnetReturnType = CimConverter.GetDotNetType(d.ReturnType);

            if (d.ReturnType == CimType.DateTime)
            {
                dotnetReturnType = typeof(DateTime);
            }
            if (d.ReturnType == CimType.DateTimeArray)
            {
                dotnetReturnType = typeof(DateTime[]);
            }
            if (dotnetReturnType == null)
            {
                returnType = SyntaxFactory.ParseTypeName("void");
            }
            else
            {
                returnType = SyntaxFactory.ParseTypeName(dotnetReturnType.FullName);
            }
            var inputParameters  = new List <NameAndType>();
            var outputParameters = new List <NameAndType>();

            foreach (var p in d.Parameters)
            {
                var type  = ResolveType(p.CimType, p.ReferenceClassName ?? p.Qualifiers["EmbeddedInstance"]?.Value as string, p.Qualifiers.IsNotNull(), typeRepo, out var isCimObject, out var isNullableValueType, out var isEnumerable, out var enumeratedType);
                var entry = new NameAndType
                {
                    IsCimObject         = isCimObject,
                    Name                = p.Name,
                    Type                = type,
                    IsNullableValueType = isNullableValueType,
                    IsEnumerable        = isEnumerable,
                    CimType             = p.CimType,
                    EnumeratedType      = enumeratedType,
                };
                if (IsIn(p))
                {
                    inputParameters.Add(entry);
                }
                if (IsOut(p))
                {
                    outputParameters.Add(entry);
                }
            }
            return(new MethodAnalysis
            {
                ReturnType = returnType,
                InputParameters = inputParameters.ToArray(),
                OutputParameters = outputParameters.ToArray()
            });
        }
        internal static string CimTypeToTypeNameDisplayString(CimType cimType)
        {
            switch (cimType)
            {
            case CimType.DateTime:
            case CimType.Instance:
            case CimType.Reference:
            case CimType.DateTimeArray:
            case CimType.InstanceArray:
            case CimType.ReferenceArray:
                return("CimInstance#" + cimType.ToString());

            default:
                return(ToStringCodeMethods.Type(
                           CimConverter.GetDotNetType(cimType)));
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="adaptedProperty"></param>
        /// <param name="value"></param>
        public override void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value)
        {
            if (adaptedProperty == null)
            {
                throw new ArgumentNullException("adaptedProperty");
            }

            if (!IsSettable(adaptedProperty))
            {
                throw new SetValueException("ReadOnlyCIMProperty",
                                            null,
                                            CimInstanceTypeAdapterResources.ReadOnlyCIMProperty,
                                            adaptedProperty.Name);
            }

            CimProperty cimProperty = adaptedProperty.Tag as CimProperty;
            object      valueToSet  = value;

            if (valueToSet != null)
            {
                // Convert only if value is not null
                Type paramType;
                switch (cimProperty.CimType)
                {
                case CimType.DateTime:
                    paramType = typeof(object);
                    break;

                case CimType.DateTimeArray:
                    paramType = typeof(object[]);
                    break;

                default:
                    paramType = CimConverter.GetDotNetType(cimProperty.CimType);
                    Dbg.Assert(paramType != null, "'default' case should only be used for well-defined CimType->DotNetType conversions");
                    break;
                }

                valueToSet = Adapter.PropertySetAndMethodArgumentConvertTo(
                    value, paramType, CultureInfo.InvariantCulture);
            }

            cimProperty.Value = valueToSet;
            return;
        }
Esempio n. 6
0
        private static TypeSyntax ResolveType(CimType cimType, string referenceClassName, bool isNotNull, IDictionary <string, CimTypeDeclaration> typeRepo, out bool isCimObject, out bool isNullableValueType, out bool isEnumerable, out TypeSyntax enumeratedType)
        {
            isEnumerable        = false;
            isCimObject         = false;
            isNullableValueType = false;
            enumeratedType      = null;
            switch (cimType)
            {
            case Microsoft.Management.Infrastructure.CimType.Instance:
            case Microsoft.Management.Infrastructure.CimType.Reference:
                if (referenceClassName != null)
                {
                    return(SyntaxFactory.ParseTypeName(typeRepo.CSharpNameOrCimInstance(referenceClassName, out isCimObject)));
                }
                return(SyntaxFactory.ParseTypeName("CimInstance"));

            case Microsoft.Management.Infrastructure.CimType.InstanceArray:
            case Microsoft.Management.Infrastructure.CimType.ReferenceArray:
                isEnumerable = true;
                if (referenceClassName != null)
                {
                    enumeratedType = SyntaxFactory.ParseTypeName(typeRepo.CSharpNameOrCimInstance(referenceClassName, out isCimObject));
                    return(SyntaxHelper.EnumerableOf(enumeratedType));
                }
                enumeratedType = SyntaxFactory.ParseTypeName("CimInstance");
                return(SyntaxHelper.EnumerableOf(enumeratedType));

            default:
                var type = CimConverter.GetDotNetType(cimType);
                if (cimType == CimType.DateTime)
                {
                    type = typeof(DateTime);
                }
                if (cimType == CimType.DateTimeArray)
                {
                    type = typeof(DateTime[]);
                }
                if (type.IsValueType && !isNotNull)
                {
                    isNullableValueType = true;
                    return(SyntaxFactory.ParseTypeName(type.FullName + "?"));
                }
                return(SyntaxFactory.ParseTypeName(type.FullName));
            }
        }