public T GetValue <T>() { T returnValue = default(T); StackTrace stackTrace = new StackTrace(); // get call stack StackFrame[] stackFrames = stackTrace.GetFrames(); StackFrame propertyStackFrame = stackFrames[1]; var m = propertyStackFrame.GetMethod(); MethodInfo mi = m as MethodInfo; System.Diagnostics.Debug.WriteLine(mi.ReturnType.FullName); string propertyName = m.Name.Substring("get_".Length); if (typeof(ILogicalId).IsAssignableFrom(mi.ReturnType)) { propertyName += "Id"; System.Diagnostics.Debug.WriteLine("Is LogicalId"); CloudFormationDictionary referenceDictionary = GetValue <CloudFormationDictionary>(propertyName); if (referenceDictionary != null) { returnValue = (T)_objects[propertyName]; } } else { returnValue = GetValue <T>(propertyName); } return(returnValue); }
public void SetValue(string propertyName, object value) { ILogicalId valueAsLogicalId = value as ILogicalId; if (valueAsLogicalId != null) { var refDictionary = new CloudFormationDictionary(); refDictionary.Add("Ref", valueAsLogicalId.LogicalId); _objects[propertyName] = valueAsLogicalId; this[propertyName] = refDictionary; } else { this[propertyName] = value; } }
private static string GetPropertyName(object value) { StackTrace stackTrace = new StackTrace(); StackFrame[] stackFrames = stackTrace.GetFrames(); StackFrame propertyStackFrame = null; MethodBase propertyMethod = null; PropertyInfo theActualProperty = null; for (int i = 1; i < stackFrames.Length - 1; i++) { propertyStackFrame = stackFrames[i]; propertyMethod = propertyStackFrame.GetMethod(); if (propertyMethod.IsSpecialName) { theActualProperty = propertyMethod.DeclaringType.GetProperty(propertyMethod.Name.Substring("get_".Length)); break; } } var jsonPropertyAttribute = theActualProperty.GetCustomAttributes <JsonPropertyAttribute>().FirstOrDefault(); string propertyName = theActualProperty.Name; if (jsonPropertyAttribute != null) { propertyName = jsonPropertyAttribute.PropertyName; } else { CloudFormationDictionary valueAsCloudFormationDictionary = value as CloudFormationDictionary; if (value is ILogicalId && !propertyName.EndsWith("Id")) { propertyName += "Id"; } } return(propertyName); }
public CloudFormationDictionary Add(string key, CloudFormationDictionary value) { base.Add(key, value); return(value); }