public static IBHoMObject AddFragment(this IBHoMObject iBHoMObject, IBHoMFragment fragment, bool replace = false) { if (iBHoMObject == null) { return(null); } IBHoMObject o = iBHoMObject.DeepClone(); int index = o.Fragments.FindIndex(x => x.GetType() == fragment.GetType()); if (index >= 0) { if (replace) { o.Fragments[index] = fragment; } else { Reflection.Compute.RecordError("That fragment already exists on this object. If you would like to replace the existing fragment set the 'replace' input to 'true'"); } } else { o.Fragments.Add(fragment); } return(o); }
public static IBHoMObject AddFragment(this IBHoMObject iBHoMObject, IBHoMFragment fragment, bool replace = false) { if (iBHoMObject == null) { return(null); } IBHoMObject o = iBHoMObject.DeepClone(); o.Fragments = new List <IBHoMFragment>(iBHoMObject.Fragments); if (o.Fragments.Contains(fragment)) { if (replace) { o.Fragments[o.Fragments.IndexOf(fragment)] = fragment; } else { Reflection.Compute.RecordError("That fragment already exists on this object. If you would like to replace the existing fragment set the 'replace' input to 'true'"); } } else { o.Fragments.Add(fragment); } return(o); }
public static IBHoMObject AddFragment(this IBHoMObject iBHoMObject, IBHoMFragment fragment, bool replace = false) { if (iBHoMObject == null) { return(null); } IBHoMObject o = iBHoMObject.DeepClone(); if (!replace) { o.Fragments.Add(fragment); } else { o.Fragments.AddOrReplace(fragment); } return(o); }
public static IEnvironmentObject AddFragment(this IEnvironmentObject environmentObject, IBHoMFragment fragment) { if (environmentObject == null) { return(null); } environmentObject.Fragments.Add(fragment); return(environmentObject); }
public static bool TryGetValue(this FragmentSet fragmentSet, Type fragmentType, out IBHoMFragment fragment) { if (fragmentType == null) { throw new ArgumentNullException($"Passed fragment type is null."); } if (!typeof(IBHoMFragment).IsAssignableFrom(fragmentType)) { throw new ArgumentException($"Passed type {fragmentType} is not an IBHoMFragment."); } if (fragmentSet != null && fragmentSet.Contains(fragmentType)) { fragment = fragmentSet[fragmentType]; return(true); } fragment = default(IBHoMFragment); return(false); }