Пример #1
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimInstance"/> with given properties.
        /// </para>
        /// </summary>
        /// <param name="cimClass"></param>
        /// <param name="properties"></param>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">See CimProperty.Create.</exception>
        /// <exception cref="ArgumentException">CimProperty.Create.</exception>
        private CimInstance CreateCimInstance(
            CimClass cimClass,
            IDictionary properties,
            NewCimInstanceCommand cmdlet)
        {
            CimInstance cimInstance = new(cimClass);

            if (properties == null)
            {
                return(cimInstance);
            }

            List <string> notfoundProperties = new();

            foreach (string property in properties.Keys)
            {
                if (cimInstance.CimInstanceProperties[property] == null)
                {
                    notfoundProperties.Add(property);
                    cmdlet.ThrowInvalidProperty(notfoundProperties, cmdlet.CimClass.CimSystemProperties.ClassName, @"Property", action, properties);
                    return(null);
                }

                object propertyValue = GetBaseObject(properties[property]);
                cimInstance.CimInstanceProperties[property].Value = propertyValue;
            }

            return(cimInstance);
        }
Пример #2
0
        private CimInstance CreateCimInstance(CimClass cimClass, IDictionary properties, NewCimInstanceCommand cmdlet)
        {
            CimInstance cimInstance;
            CimInstance cimInstance1 = new CimInstance(cimClass);

            if (properties != null)
            {
                List <string> strs       = new List <string>();
                IEnumerator   enumerator = properties.Keys.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string current = (string)enumerator.Current;
                        if (cimInstance1.CimInstanceProperties[current] != null)
                        {
                            object baseObject = base.GetBaseObject(properties[current]);
                            cimInstance1.CimInstanceProperties[current].Value = baseObject;
                        }
                        else
                        {
                            strs.Add(current);
                            cmdlet.ThrowInvalidProperty(strs, cmdlet.CimClass.CimSystemProperties.ClassName, "Property", "New-CimInstance", properties);
                            cimInstance = null;
                            return(cimInstance);
                        }
                    }
                    return(cimInstance1);
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                return(cimInstance);
            }
            else
            {
                return(cimInstance1);
            }
        }
Пример #3
0
 /// <summary>
 /// <para>
 /// Create <see cref="CimInstance"/> with given properties.
 /// </para>
 /// </summary>
 /// <param name="cimClass"></param>
 /// <param name="properties"></param>
 /// <param name="cmdlet"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">See CimProperty.Create</exception>
 /// <exception cref="ArgumentException">CimProperty.Create</exception>
 private CimInstance CreateCimInstance(
     CimClass cimClass,
     IDictionary properties,
     NewCimInstanceCommand cmdlet)
 {
     CimInstance cimInstance = new CimInstance(cimClass);
     if (properties == null)
     {
         return cimInstance;
     }
     List<string> notfoundProperties = new List<string>();
     foreach (string property in properties.Keys)
     {
         if (cimInstance.CimInstanceProperties[property] == null)
         {
             notfoundProperties.Add(property);
             cmdlet.ThrowInvalidProperty(notfoundProperties, cmdlet.CimClass.CimSystemProperties.ClassName, @"Property", action, properties);
             return null;
         }
         object propertyValue = GetBaseObject(properties[property]);
         cimInstance.CimInstanceProperties[property].Value = propertyValue;
     }
     return cimInstance;
 }
Пример #4
0
		private CimInstance CreateCimInstance(CimClass cimClass, IDictionary properties, NewCimInstanceCommand cmdlet)
		{
			CimInstance cimInstance;
			CimInstance cimInstance1 = new CimInstance(cimClass);
			if (properties != null)
			{
				List<string> strs = new List<string>();
				IEnumerator enumerator = properties.Keys.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						string current = (string)enumerator.Current;
						if (cimInstance1.CimInstanceProperties[current] != null)
						{
							object baseObject = base.GetBaseObject(properties[current]);
							cimInstance1.CimInstanceProperties[current].Value = baseObject;
						}
						else
						{
							strs.Add(current);
							cmdlet.ThrowInvalidProperty(strs, cmdlet.CimClass.CimSystemProperties.ClassName, "Property", "New-CimInstance", properties);
							cimInstance = null;
							return cimInstance;
						}
					}
					return cimInstance1;
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				return cimInstance;
			}
			else
			{
				return cimInstance1;
			}
		}