public PrimitiveTypeSerializer(ResourceType resourceType, ResourceProperty resourceProperty) : base(resourceType) { object defaultValue; object[] resourceTypeKind = new object[2]; resourceTypeKind[0] = resourceType.ResourceTypeKind; resourceTypeKind[1] = ResourceTypeKind.Primitive; ExceptionHelpers.ThrowArgumentExceptionIf("resourceType", resourceType.ResourceTypeKind != ResourceTypeKind.Primitive, new ExceptionHelpers.MessageLoader(SerializerBase.GetInvalidArgMessage), resourceTypeKind); this.defaultValue = null; if (resourceProperty != null) { if ((resourceProperty.Kind & ResourcePropertyKind.Primitive) != ResourcePropertyKind.Primitive || resourceProperty.ResourceType.InstanceType != resourceType.InstanceType) { throw new ArgumentException("resourceProperty"); } else { PropertyCustomState customState = resourceProperty.GetCustomState(); PrimitiveTypeSerializer primitiveTypeSerializer = this; if (customState != null) { defaultValue = customState.DefaultValue; } else { defaultValue = null; } primitiveTypeSerializer.defaultValue = defaultValue; this.name = resourceProperty.Name; } } }
internal static object GetValue(ResourceProperty property, object clrObject) { string name; int num; int num1 = -1; string[] strArrays = null; if (property.GetCustomState() != null && property.GetCustomState().PsProperty != null) { char[] chrArray = new char[1]; chrArray[0] = '.'; strArrays = property.GetCustomState().PsProperty.Split(chrArray); num1 = 0; } do { if (num1 > -1) { name = strArrays[num1]; } else { name = property.Name; } string str = name; if (clrObject as PSObject == null) { clrObject = TypeSystem.GetPropertyValue(clrObject, str, false); } else { PSObject pSObject = clrObject as PSObject; PSPropertyInfo item = pSObject.Properties[str]; if (item != null) { try { clrObject = item.Value; } catch (GetValueException getValueException1) { GetValueException getValueException = getValueException1; TraceHelper.Current.SerializationPropertyNotFound(str, getValueException.Message); if (!property.ResourceType.IsPrimitive() || property.ResourceType.IsNullable()) { clrObject = null; } else { throw new PSObjectSerializationFailedException(string.Format(Resources.PropertyRetrievalFailed, str, getValueException.Message)); } } } else { object[] objArray = new object[1]; objArray[0] = str; TraceHelper.Current.SerializationPropertyNotFound(str, string.Format(CultureInfo.CurrentCulture, Resources.PropertyNotFoundInPSObject, objArray)); if (!property.ResourceType.IsPrimitive() || property.ResourceType.IsNullable()) { clrObject = null; break; } else { object[] objArray1 = new object[1]; objArray1[0] = str; throw new PSObjectSerializationFailedException(string.Format(CultureInfo.CurrentCulture, Resources.PropertyNotFoundInPSObject, objArray1)); } } } if (clrObject == null || strArrays == null) { break; } num = num1 + 1; num1 = num; } while (num < (int)strArrays.Length); return clrObject; }
public ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty) { ResourceAssociationSet resourceAssociationSet; if (resourceSet == null || resourceType == null) { return null; } else { if (resourceType.Properties.Contains(resourceProperty)) { Microsoft.Management.Odata.Schema.Schema.AssociationType associationType = (resourceProperty.GetCustomState() as ReferenceCustomState).AssociationType; if (associationType != null) { List<ResourceAssociationSet>.Enumerator enumerator = associationType.WcfClass.GetEnumerator(); try { while (enumerator.MoveNext()) { ResourceAssociationSet current = enumerator.Current; if (current.End1.ResourceSet != resourceSet || current.End1.ResourceType != resourceType || current.End1.ResourceProperty != resourceProperty) { if (current.End2.ResourceSet != resourceSet || current.End2.ResourceType != resourceType || current.End2.ResourceProperty != resourceProperty) { continue; } resourceAssociationSet = current; return resourceAssociationSet; } else { resourceAssociationSet = current; return resourceAssociationSet; } } return null; } finally { enumerator.Dispose(); } return resourceAssociationSet; } else { return null; } } else { return null; } } }