public object NewInstance(IProject proj, bool initialize) { object ob = CreateInstance(proj); string name = WrappedTypeName.ToLower() + (++counter).ToString(); int i = name.LastIndexOf('.'); if (i != -1) { if (i < name.Length) { name = name.Substring(i + 1); } else { name = name.Replace(".", ""); } } ObjectWrapper ow = CreateWrapper(); try { ow.Loading = true; ObjectWrapper.Bind(proj, this, ow, ob, !initialize); // Initialize the properties after creating the wrapper, since some properties // may be implemented in the wrapper foreach (ItemGroup group in groups) { foreach (ItemDescriptor item in group) { PropertyDescriptor prop = item as PropertyDescriptor; if (prop != null && prop.InitWithName) { prop.SetValue(ob, name); } } } } finally { ow.Loading = false; } return(ob); }
internal protected virtual CodeExpression GenerateObjectCreation(GeneratorContext ctx) { if (ClassDescriptor.InitializationProperties != null) { CodeExpression[] paramters = new CodeExpression [ClassDescriptor.InitializationProperties.Length]; for (int n = 0; n < paramters.Length; n++) { PropertyDescriptor prop = ClassDescriptor.InitializationProperties [n]; paramters [n] = ctx.GenerateValue(prop.GetValue(Wrapped), prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated(Wrapped)); } return(new CodeObjectCreateExpression(WrappedTypeName.ToGlobalTypeRef(), paramters)); } else { return(new CodeObjectCreateExpression(WrappedTypeName.ToGlobalTypeRef())); } }
public object NewInstance(IProject proj, bool initialize) { object ob = CreateInstance(proj); string name = WrappedTypeName.ToLower() + (++counter).ToString(); int i = name.LastIndexOf('.'); if (i != -1) { if (i < name.Length) { name = name.Substring(i + 1); } else { name = name.Replace(".", ""); } } foreach (ItemGroup group in groups) { foreach (ItemDescriptor item in group) { PropertyDescriptor prop = item as PropertyDescriptor; if (prop != null && prop.InitWithName) { prop.SetValue(ob, name); } } } ObjectWrapper ow = CreateWrapper(); ObjectWrapper.Bind(proj, this, ow, ob, !initialize); return(ob); }